
We all know about Cascading Style Sheet and its importance in Styling our web pages. Let us know three major types of CSS inline, internal (embedded), and external CSS.
It is important to know all the methods of integrating CSS in HTML documents for our web development project. In this article, we will learn in detail the types of CSS in web development and their uses.
CSS is very important for web development as it defines how HTML elements are rendered and appear to the users. CSS can be applied in the header section of HTML or it can be aligned inline with the individual HTML elements. Based on these factors CSS is divided into three major categories given below.
|
Example of Inline CSS |
| <!DOCTYPE html> <html> <head> <title>Inline CSS Example</title> </head> <body> <h1 style="color: blue; text-align: center;">This is a Heading</h1> <p style="font-size: 20px; color: green;">This is a paragraph with inline CSS.</p> </body> </html> |
|
Example of Internal CSS |
| <!DOCTYPE html> <html> <head> <title>Internal CSS Example</title> <style> body { background-color: lightblue; } h1 { color: navy; text-align: center; } p { font-size: 18px; color: darkgreen; } </style> </head> <body> <h1>This is a Heading</h1> <p>This is a paragraph with internal CSS.</p> </body> </html> |
|
Example of External CSS |
| <!DOCTYPE html> <html> <head> <title>External CSS Example</title> <link rel="stylesheet" type="text/css" href="external.css"> </head> <body> <h1>This is a Heading</h1> <p>This is a paragraph with external CSS.</p> </body> </html> |
| body { background-color: lightgray; } h1 { color: darkblue; text-align: center; } p { font-size: 16px; color: black; } |
| Inline CSS | Internal CSS | External CSS |
| This CSS property can be individually applied to specific HTML tags. | It is applied in the <head> section of the HTML document. | It is applied in a separate CSS file. |
| It is an ideal practice for smaller web development projects. | It is an ideal practice for medium to large projects. | It is an ideal practice for smaller to web pages having multiple pages. |
| <element style="property: value;”> | <style> selector { property: value; } </style> | selector { property: value; |
| It affects only the element in which it is applied. | It affects the entire HTML document where the <style> element is defined. | It can affect multiple HTML document pages. |
| It is not reusable | It is not reusable | It can be reused for multiple HTML pages. |
| It can possibly slow down the page loading speed if used frequently. | The same goes for Internal CSS | It is fastest as CSS file is cached by the browser and can be reused across multiple HTML pages. |
| Simple and quick to implement | Keeps the HTML elements organised | Gives a centralised control over HTML elements |