HTML uses tags to define different elements on a web page. For example, the <html>
tag is the root element, <head>
contains meta - information about the page, and <body>
holds the visible content.
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to my page</h1>
<p>This is a paragraph of text.</p>
</body>
</html>
CSS selectors are used to select HTML elements to apply styles. There are several types of selectors:
p {
color: blue;
}
<p class="highlight">This is a highlighted paragraph.</p>
.highlight {
background - color: yellow;
}
<div id="main - content">This is the main content.</div>
#main - content {
border: 1px solid black;
}
The box model describes how elements are laid out on a page. It consists of content, padding, border, and margin.
div {
width: 200px;
padding: 20px;
border: 1px solid black;
margin: 10px;
}
Inline CSS is applied directly to an HTML element using the style
attribute.
<p style="color: red; font - size: 18px;">This is a paragraph with inline CSS.</p>
Internal CSS is placed within the <style>
tags in the <head>
section of an HTML document.
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
color: green;
}
</style>
</head>
<body>
<h2>This is a heading with internal CSS.</h2>
</body>
</html>
External CSS is stored in a separate .css
file and linked to an HTML document using the <link>
tag.
styles.css
body {
background - color: lightgray;
}
index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>Page with external CSS.</p>
</body>
</html>
You can control font - family, size, weight, and line - height to improve readability.
body {
font - family: Arial, sans - serif;
font - size: 16px;
line - height: 1.6;
}
h1 {
font - weight: bold;
font - size: 32px;
}
Colors can be specified using names, hexadecimal values, RGB, or RGBA. Backgrounds can be set to colors or images.
body {
background - color: #f4f4f4;
}
.hero - section {
background - image: url('hero - image.jpg');
color: white;
}
CSS offers various layout techniques such as floats, flexbox, and grid.
.container {
display: flex;
justify - content: space - around;
}
.item {
width: 200px;
height: 200px;
background - color: lightblue;
}
Keep your CSS code organized by using comments, grouping related styles, and following a naming convention. For example, use BEM (Block, Element, Modifier) naming for classes.
/* Header section */
.header {
background - color: #333;
}
.header__logo {
width: 100px;
}
Use media queries to make your website look good on different devices.
@media (max - width: 768px) {
.container {
flex - direction: column;
}
}
Minify your CSS files to reduce file size and improve loading times. Also, avoid using too many CSS selectors and inline styles.
Understanding the CSS glossary in the context of HTML is essential for creating modern, visually appealing, and user - friendly websites. By mastering the fundamental concepts, using the right usage methods, following common practices, and implementing best practices, you can take your web development skills to the next level. Whether you are a beginner or an experienced developer, these principles will help you build better websites more efficiently.