In this topic we will learn how to use html with CSS. CSS(Cascading Style Sheets) is used to apply style on the web page which is made up of HTML elements.
CSS describes the look of the webpage and it provides different style properties such as text-color, background-color, padding, margin, and many more to style webpage.
CSS saves time, you can write CSS once and then reuse that sheet in multiple HTML pages.
Three ways to apply CSS:
It is the best way to keep the styles in separate CSS files. You can define a style for each HTML element and apply it to multiple Web pages as you want.
The inline CSS helps you apply CSS to specific HTML elements. The style attribute is used in the HTML element to apply inline CSS. You can apply multiple properties as you want, you just have to separate each property by a semicolon(;).
The internal CSS is used to add a unique style for a single document.
The internal CSS is defined in <head> section of the HTML page inside the <style> tag.
The class and id attributes are used with internal CSS.
An external style sheet is a separate CSS file that only contains style code using the class name. id name etc.
Using an external style sheet you can change the look of the entire web page by changing one file.
You can use this CSS file in any HTML file by including it in the <head> section of the HTML page.
If you have multiple HTML pages for an application which have similar CSS, then you can use external CSS.
You can write external CSS in any editor and save that CSS file with .css extension.
The CSS color property is used to set the color of the text.
The CSS font-family property is used to change the font of the text.
The CSS font-size property is used to increase or decrease the size of the text.
The CSS border property is used to set the border around the HTML element.
The CSS padding property is used to set space between the text and the border.
CSS Margin property is used to define the space around HTML elements.
The external style sheets can be referenced with a full URL or with a path relative to the current web page.
Following example uses a full URL to link to a style sheet.
Following example links to a style sheet located in the html folder on the current web site.
Following example links to a style sheet located in the same folder as the current page.