DEV Community

Alex Gonzalez
Alex Gonzalez

Posted on

Introduction to CSS: Transforming Web Pages with Style

CSS, or Cascading Style Sheets, is a language used to style and present web pages. While HTML provides the structure and content of a page, CSS brings it to life by defining how that content will look. From color and typography to layout and arrangement.

What is CSS?

CSS is a styling language that describes how HTML elements should be presented on a web page. It allows control over aspects such as color, font, size, and layout of HTML elements, as well as the arrangement and positioning of those elements on the page.

Basic Syntax of CSS

The syntax of CSS consists of a set of rules that specify how style should be applied to HTML elements. Each rule consists of a selector and a set of style declarations, which define the properties and values to be applied to the selected elements.

selector {
    property: value;
    /* Comment */
}
Enter fullscreen mode Exit fullscreen mode
  • Selector: Specifies which HTML elements will be affected by the style rule.
  • Property: Defines the aspect you want to change.
  • Value: Specifies the value to be applied to the property
  • Comments: Used to add notes in the CSS code that are not interpreted as part of the style.

Applying Styles to HTML Elements

There are several ways to apply CSS styles to HTML elements:

  1. Inline Styles: Applied directly to an element using the style attribute.
<p style="color: blue; font-size: 16px;">Paragraph with inline styles.</p>
Enter fullscreen mode Exit fullscreen mode
  1. Internal Styles: Defined within the <style> tag in the <head> section of the HTML document.
<head>
    <style>
        p {
            color: blue;
            font-size: 16px;
        }
    </style>
</head>
Enter fullscreen mode Exit fullscreen mode
  1. External Styles: Defined in a separate CSS file and linked to the HTML document using the <link> tag in the <head> section.
<head>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
Enter fullscreen mode Exit fullscreen mode

Key CSS Properties

CSS offers a wide range of properties to customize the style of HTML elements. Some of the most common properties include:

  • color: Defines the text color.
  • font-family: Specifies the font used for text.
  • font-size: Sets the font size.
  • margin: Controls the space around an element.
  • padding: Defines the internal space of an element.
  • border: Sets the border around an element.
  • background-color: Defines the background color of an element.

For more information about CSS Properties: https://www.dofactory.com/css/properties

Advancing with CSS

As you become familiar with CSS, you can explore more advanced techniques such as using more specific selectors, responsive design to adapt the page to different devices, and animation to add visual interactivity.

With this introduction to CSS, you're ready to start styling your web pages and creating captivating visual experiences on the web. Experiment and have fun exploring the power of web design with CSS!

Top comments (0)