How to insert CSS to create styles for HTML pages
When the browser reads the format file (stylesheet), it will format the HTML text according to the information in that format file.
3 ways to add CSS
There are 3 ways to add formatting files to HTML documents.
- Internal file format
- External format file
- In-line
External format file
With an external style sheet, you can change the look of the whole website, just change a single file, Each page will have a reference to this external file in the element. located in the section
.
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
.
Title
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
like this:
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
There will be navy blue.
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:
- Inline format (inside HTML elements)
- Internal and external format files (in the head section)
- Browser default
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
You should read it
May be interested
- MS Word - Lesson 14: Create Web Pagessimple web pages can be created in word using the save as feature. in a web document, you can insert images and hyperlinks. to view documents as a website:
- Iframe in HTMLin html, iframe is used to display a web page within another website.
- List in HTMLthis tutorial explains how to create lists in html.
- Introduction to HTMLa few basic things to know about html before starting to learn this language.
- How to style pages symmetrically on Wordsymmetrical page numbering in word is basically the same as when you numbered pages on word, but will choose symmetrical mode.
- How to Create a Link With Simple HTML Programmingonce you've created a couple web pages using html, you'll want to connect them into a larger site. learn how to link from one page of your site to another, or to any other site on the internet. you can even send your visitors to a specific...
- Caption tags in HTMLthe comment tag is used to insert comments into the source code of html.
- How to number a PDF pagepdf page numbers are not available as options for page numbering in word or page numbering in excel.
- File path in HTMLthe article explains how to refer to the file path in html.
- 5 steps to learn a dynamic HTML web component profilehtml is an important part of websites we still use every day. however, not everyone can understand how a website is structured.