Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

css

What are the basics of CSS?

Sheza Munir

CSS stands for Cascading Style Sheets. It consists of the properties that style webpage code (usually HTML). It is not a programming or markup language, but rather a stylesheet language. We use this to specifically style certain areas of the web page’s content. It can also be used to style React components.

Ruleset

The following illustration shows how we declare a CSS property. The structure is called a ruleset.

A ruleset has the following attributes:

Selector

This specifies the part of HTML code that will be styled by the ruleset. It uses the class name or tag from HTML (e.g. <p>) to specify the CSS styling.

Declaration

This part specifies the styling properties. You can style the font, color, or alignment of the text here.

Properties

This part of the declaration specifies which characteristic will be styled.

Property value

This part specifies how the property will be styled.

  • The ruleset must be enclosed with curly brackets, {}
  • Each statement in the ruleset must be terminated with a semi-colon

Mutiple elements

If multiple elements require the same styling, they can all be declared as selectors. The following snippet shows how this may be done:

p, h1 {
  font-family: "Times New Roman";
}

Types of CSS styling

There are three ways to use CSS styling:

  1. Inline CSS
    The CSS components are enclosed within the HTML tags. This is done by using the style attribute.
  2. Internal/embedded CSS
    The CSS components are declared for the whole page in the same file as the HTML code. We do this in the head section of the HTML code.
  3. External CSS
    The CSS code is contained in a separate file, which is linked to the HTML file. The external CSS file uses selectors to refer to and style the HTML code snippets.

RELATED TAGS

css

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring