Table of contents
1.
Introduction
2.
Example
2.1.
HTML File (index.html)
2.2.
CSS File (styles.css)
3.
List of Complete CSS Properties
3.1.
1. Background Properties
3.1.1.
Example:
3.2.
2. Text Properties
3.2.1.
Example:
3.3.
3. Font Properties
3.3.1.
Example:
3.4.
4. Margin and Padding
3.4.1.
Example:
3.5.
5. Border Properties
3.5.1.
Example:
3.6.
6. Box Model Properties
3.6.1.
Example:
3.7.
7. Flexbox Properties
3.7.1.
Example:
3.8.
8. Grid Properties
3.8.1.
Example:
3.9.
9. Positioning Properties
3.9.1.
Example:
3.10.
10. Animation and Transition Properties
3.10.1.
Example:
4.
Frequently Asked Questions
4.1.
What are CSS properties in HTML?
4.2.
Why are CSS properties important?
4.3.
How can I apply CSS properties in HTML?
5.
Conclusion
Last Updated: Feb 9, 2025
Easy

CSS Properties in HTML

Author Sinki Kumari
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

CSS properties in HTML are used to control the appearance and layout of web pages. They define styles such as colors, fonts, spacing, and positioning, allowing developers to enhance the user experience. CSS properties can be applied inline, internally, or externally for better design management. 

In this article, you will learn about different CSS properties, their syntax, and how to use them effectively to style HTML elements.

Example

Let's start with a simple example to understand how CSS properties work in HTML:

HTML File (index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Properties Example</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <h1>Welcome to CSS Styling</h1>
    <p>This is an example of applying CSS properties in HTML.</p>
</body>
</html>

CSS File (styles.css)

body {
    background-color: #f0f0f0;
    font-family: Arial, sans-serif;
}

h1 {
    color: blue;
    text-align: center;
    font-size: 28px;
}

p {
    color: black;
    font-size: 16px;
    text-align: justify;
}

Output:

 

Output

A web page with a light gray background, a blue heading centered, and a justified paragraph with black text.

List of Complete CSS Properties

Below is a list of commonly used CSS properties in HTML along with their explanations and examples.

1. Background Properties

These properties control the background of elements.

Example:

body {
    background-color: lightblue;
    background-image: url('background.jpg');
    background-repeat: no-repeat;
    background-size: cover;
}

2. Text Properties

These properties control text appearance.

Example:

h1 {
    color: red;
    font-size: 24px;
    text-align: center;
    text-transform: uppercase;
}

3. Font Properties

These properties define font style and appearance.

Example:

p {
    font-family: 'Arial', sans-serif;
    font-size: 18px;
    font-weight: bold;
}

4. Margin and Padding

These properties control spacing around elements.

Example:

div {
    margin: 20px;
    padding: 10px;
    border: 1px solid black;
}

5. Border Properties

These properties define element borders.

Example:

div {
    border: 2px solid red;
    border-radius: 10px;
}

6. Box Model Properties

These define the size and layout of elements.

Example:

div {
    width: 200px;
    height: 100px;
    padding: 10px;
    margin: 20px;
}

7. Flexbox Properties

These properties help in creating flexible layouts.

Example:

.container {
    display: flex;
    justify-content: center;
    align-items: center;
}

8. Grid Properties

These properties help in designing grid-based layouts.

Example:

.container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

9. Positioning Properties

These define how elements are positioned.

Example:

div {
    position: absolute;
    top: 50px;
    left: 100px;
}

10. Animation and Transition Properties

These add effects and animations to elements.

Example:

.button {
    background-color: blue;
    color: white;
    padding: 10px;
    transition: background-color 0.5s ease;
}

.button:hover {
    background-color: red;
}

Frequently Asked Questions

What are CSS properties in HTML?

CSS properties are rules that define the appearance of HTML elements. They control aspects like colors, fonts, layouts, spacing, and animations.

Why are CSS properties important?

CSS properties enhance user experience by making web pages visually appealing, organized, and responsive across different devices.

How can I apply CSS properties in HTML?

CSS properties can be applied using inline styles, internal styles within a <style> tag, or external stylesheets linked using the <link> tag.

Conclusion

In this article, we learned CSS properties in HTML, their role in styling web pages, and how they enhance the visual presentation of elements. We discussed different types of CSS properties, including layout, typography, colors, and positioning. Understanding these properties helps developers create responsive and visually appealing websites with better user experience and design consistency.

Live masterclass