HTML Tutorial
HTML XHTML
HTML Media
HTML Advanced
Here's a tutorial on HTML CSS Encyclopedia and Common Embedding Methods:
HTML (Hypertext Markup Language) and CSS (Cascading Style Sheets) are essential tools for creating web pages. HTML provides the structure and content of a web page, while CSS provides the visual styling and layout. In this tutorial, we'll cover some common embedding methods for HTML and CSS.
One common way to add CSS to an HTML document is to embed it directly in the HTML code. You can do this by using the <style>
tag in the head section of your HTML document. Here's an example:
<!DOCTYPE html> <html> <head> <title>My Web Page</title> <style> body { background-color: #eee; } h1 { color: blue; } </style> </head> <body> <h1>Welcome to my web page!</h1> <p>This is some text.</p> </body> </html>
In this example, the CSS is embedded within the <style>
tags in the head section of the HTML document. The CSS rules apply to the entire document, with the background color of the body set to light gray and the color of the h1 tag set to blue.
Another way to add CSS to an HTML document is to link to an external CSS file. This is a more efficient method, as the CSS rules can be reused across multiple pages. Here's an example:
<!DOCTYPE html> <html> <head> <title>My Web Page</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <h1>Welcome to my web page!</h1> <p>This is some text.</p> </body> </html>
In this example, the CSS is stored in an external file called "style.css", which is linked to in the head section of the HTML document using the <link>
tag. The CSS rules in "style.css" apply to the entire document, with the background color of the body set to light gray and the color of the h1 tag set to blue.
Inline CSS is another way to add CSS to an HTML document. This involves adding the CSS rules directly to the HTML element using the style
attribute. Here's an example:
<!DOCTYPE html> <html> <head> <title>My Web Page</title> </head> <body> <h1 style="color: blue;">Welcome to my web page!</h1> <p>This is some text.</p> </body> </html>
In this example, the CSS rule for the color of the h1 tag is added inline using the style
attribute. Inline CSS is useful for applying CSS to a single element, but it can be difficult to maintain and update as the document grows.
These are just a few common methods for embedding CSS in HTML. By using these methods, you can create visually appealing web pages with consistent styling and layout.
Embedding CSS in HTML:
You can embed CSS directly within an HTML document using the <style>
tag within the <head>
section. Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { background-color: #f0f0f0; font-family: 'Arial', sans-serif; } h1 { color: #333; } </style> <title>Embedded CSS Example</title> </head> <body> <h1>Hello, World!</h1> <p>This is an example of embedding CSS in HTML.</p> </body> </html>
Linking external CSS in HTML: Linking an external CSS file is a common practice for separating styles from HTML. Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="styles.css"> <title>External CSS Example</title> </head> <body> <h1>Hello, World!</h1> <p>This is an example of linking external CSS in HTML.</p> </body> </html>
Embedding CSS frameworks in HTML: You can embed CSS frameworks like Bootstrap directly in your HTML document. Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <title>Bootstrap Example</title> </head> <body> <h1 class="text-primary">Hello, World!</h1> <p class="lead">This is an example of embedding Bootstrap CSS in HTML.</p> </body> </html>
HTML CSS media queries embedding: Embed media queries in CSS for responsive design. Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { font-family: 'Arial', sans-serif; } @media (min-width: 768px) { body { background-color: #f0f0f0; } } </style> <title>Media Queries Example</title> </head> <body> <h1>Hello, World!</h1> <p>This is an example of embedding CSS media queries in HTML.</p> </body> </html>
Embedding fonts with CSS in HTML:
Embedding fonts using CSS @font-face
. Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> @font-face { font-family: 'CustomFont'; src: url('customfont.woff2') format('woff2'); } body { font-family: 'CustomFont', sans-serif; } </style> <title>Font Embedding Example</title> </head> <body> <h1>Hello, World!</h1> <p>This is an example of embedding fonts with CSS in HTML.</p> </body> </html>
HTML CSS script tag embedding:
You can also embed CSS within the <style>
tag directly in the body of the HTML document. Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Embedded CSS Example</title> </head> <body> <style> body { background-color: #f0f0f0; font-family: 'Arial', sans-serif; } h1 { color: #333; } </style> <h1>Hello, World!</h1> <p>This is an example of embedding CSS in HTML using the script tag.</p> </body> </html>