1.

What are the different ways of adding CSS styles to your HTML file?

Answer»

There are three ways of adding CSS style rules to an HTML file.

1. Inline CSS - This is used to apply styles to a single HTML element, by making use of the style attribute.

Example,

<div style=“color: red;”> This div has inline CSS applied </div>

2. INTERNAL or Embedded CSS - This is used to apply styles for a single HTML page. The style rules are defined in the <head> SECTION of that HTML page, enclosed within the <style> </style> tags.

Example,

<!DOCTYPE html> <html>      <head>           <style>                div { color: red; }                p { color: blue; }           </style>      </head>      <body>           <div> This is a div with embedded CSS </div>           <p>This is a paragraph with embedded CSS </p>      </body> </html>

3. External CSS - This is the most efficient way to ADD CSS styles. Using an external stylesheet, you can add styles to many HTML pages at once. You use the <link> tag to link your HTML web pages to the external CSS file.

Example,

  <link rel="stylesheet" HREF="styles.css">


Discussion

No Comment Found