Internal CSS
Learn how to write CSS inside an HTML document using the style element.
What is Internal CSS?
Internal CSS is CSS written inside a <style> element in the <head> section of an HTML page.
It is useful when one HTML page needs its own collection of CSS styles.
Internal CSS Diagram
Basic Structure
<html>
<head>
<style>
p {
color: blue;
}
</style>
</head>
<body>
<p>Hello CSS</p>
</body>
</html>
The <style> element contains the CSS rules used to style the HTML elements.
Example 1: Style a Heading
Code
<style>
h1 {
color: blue;
font-size: 30px;
}
</style>
<h1>
Welcome CIIT Student 👨🏫👀.
</h1>
Simple Explanation
The h1 selector selects the heading. The CSS changes its color to blue and its font size to 30px.
Welcome CIIT Student 👨🏫👀.
Example 2: Style Multiple Elements
Code
<style>
h1 {
color: blue;
}
p {
color: green;
font-size: 18px;
}
</style>
<h1>
CSS Tutorial
</h1>
<p>
Learn Student CIIT Institute 👀🤓.
</p>
Simple Explanation
Internal CSS can contain multiple CSS rules. Each selector can style a different HTML element.
CSS Tutorial
Learn Student CIIT Institute 👀🤓.
Example 3: Change Background Color
Code
<style>
body {
background-color: lightgray;
}
</style>
<h1>
CSS Background
</h1>
Simple Explanation
The background-color property changes the background color.
CSS Background
Where is Internal CSS Written?
Internal CSS is normally written inside the <head> section of the HTML document.
<head>
<style>
body {
background-color: lightgray;
}
</style>
</head>
Advantages of Internal CSS
- Easy to use for a single HTML page.
- Page-specific CSS can stay in one place.
- No separate CSS file is required.
Limitations of Internal CSS
- Styles cannot be easily shared across many pages.
- Large HTML files can become difficult to maintain.
- Reusing the same styles across multiple pages is harder.
Internal CSS is written inside the <style> element, usually inside the <head> section.
Summary
Internal CSS is written inside the <style> element of an HTML document. It allows multiple CSS rules to style elements on the same page.