When we add CSS in HTML file, the browser reads a style sheet, format the document according to information in the style sheet.
Following are three ways to insert CSS in HTML file.
External CSS
Internal CSS
Inline CSS
External CSS
With an external CSS, you can apply CSS on multiple pages. The HTML page must include a reference to the external style sheet file inside the element, in the head section.
The inline CSS styles cannot be reused anywhere else.
To style pseudo-codes and pseudo-classes with inline CSS is not possible.
These styles are difficult to be edited because they are not stored at a single place.
Inline CSS does not provide browser cache advantages.
Multiple Style Sheets
If more than one properties have been defined for the same selector (element) in different style sheets, the value from the last read style sheet will be used.
Consider that an external style sheet has the following style for the <h2> element:
h2 {
background-color: yellow;
}
Then, consider that an internal style sheet has the following style for the <h2> element:
h2 {
background-color: red;
}
Example:
The last read style sheet will be used. So, if the internal style is defined after the link to the external style sheet, the <h2> elements will be “red”:
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok