Learn HTML
Lesson 1 - Overview Of The Web And HTML
Lesson 2 - HTML Tags And Elements
Lesson 3 - Images And Multimedia
Lesson 4 - Writing Your First HTML Page
Lesson 5 - Overview Of CSS
Lesson 6 - CSS Selectors And Properties
Lesson 8 - Box Model
Lesson 9 - Positioning And Layout
Lesson 10 - Flexbox
There are three methods to apply CSS to HTML documents: Inline styles, Internal stylesheets, and External stylesheets. Each method serves different purposes and offers varying levels of flexibility and scalability.
Inline styles allow you to apply styles directly to HTML elements using the style
attribute. This method is suitable for applying unique styles to individual elements.
<p style="color: blue; font-size: 20px;">This is a text.</p>
Internal stylesheets are defined within the <style>
tag inside the HTML document's <head>
section. This method is useful for styling a single webpage.
<!DOCTYPE html> <html> <head> <title>List of Fruits</title> <style> body { background-color: lightgrey; } h1 { color: blue; } p { font-size: 20px; } </style> </head> <body> <h1>Welcome to My Website</h1> <p>This is a paragraph styled with an internal stylesheet.</p> </body> </html>
External stylesheets allow you to create separate CSS files. The HTML document links to this CSS file using the <link>
tag in the <head>
section. This method is ideal for styling multiple web pages consistently and efficiently, making it suitable for large projects.
Example of an External CSS file:
File name: styles.css
body { background-color: lightgrey; } h1 { color: blue; } p { font-size: 20px; }
Linking the External CSS file in your HTML document:
File name: index.html
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="styles.css"> <title>My First Website</title> </head> <body> <h1>My First Website</h1> <p>This is a paragraph styled with an external stylesheet.</p> </body> </html>
Using external stylesheets helps maintain a consistent design across multiple web pages and improves the maintainability of your project by separating content and presentation.