External format files can be written on any editor, contain no HTML elements and must be saved with the .css extension.
Here is an example of a section in the style sheet file.
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
Note: Do not add spaces between property values and units (like this margin-left: 20 px
;). but must write like this: margin-left: 20px;
Internal file format
This file should be used when each page has a different format, defined by element
Inline format
This format should be used if a specific format is applied to a particular element. To apply, add style attributes to related elements, style attributes can contain CSS properties. The example below shows how to change the color and align the element
Many file formats
If multiple properties are defined for the same selector in different format files, the value can be used from the latest style sheet reading. Assume a style sheet in addition to the element format
as follows:
h1 {
color: navy;
}
then an internal style sheet format for the element
h1 {
color: orange;
}
If the internal format is defined after the path to the external style sheet, the element
will be orange.
But if the internal format is predefined, the element
Order of stratification
What type of format should I use when there is more than one type for an HTML element? Often the order of application of the format follows the hierarchy from high to low as follows:
The inline format (within the HTML element) is of the highest priority, ie it can override the format defined in the tag or external style sheet file or browser default value.
Previous article: Syntax and Selector in CSS
The following article: Colors in CSS