Introduction to CSS

Lecture 1: Introduction to CSS

Welcome to the first lecture of “Basic to Brilliance” – your journey to mastering CSS starts here!

What is CSS?

CSS, or Cascading Style Sheets, is the language used to describe the presentation o…


This content originally appeared on DEV Community and was authored by Ridoy Hasan

Lecture 1: Introduction to CSS

Welcome to the first lecture of "Basic to Brilliance" - your journey to mastering CSS starts here!

What is CSS?

CSS, or Cascading Style Sheets, is the language used to describe the presentation of a web page. While HTML provides the structure and content, CSS is what makes the web pages look attractive and user-friendly. It controls the layout, colors, fonts, spacing, and much more.

Why is CSS Important?

  • Separation of Concerns: CSS allows you to separate content (HTML) from presentation (CSS), making your code cleaner and easier to maintain.
  • Consistency: You can apply consistent styling across multiple web pages by linking a single CSS file.
  • Responsive Design: CSS is essential for creating websites that look good on all devices, from desktops to smartphones.

Basic CSS Syntax

CSS is made up of rules that target HTML elements. Each rule consists of a selector and a declaration block.

selector {
  property: value;
}
  • Selector: Targets the HTML element you want to style.
  • Property: The aspect of the element you want to change (e.g., color, font-size).
  • Value: The specific value you want to apply to the property.
Example:

Let’s say you want to change the color of all <h1> elements to blue.

HTML:

<h1>Hello, World!</h1>

CSS:

h1 {
  color: blue;
}

This simple rule will turn the text in all <h1> elements to blue.

Adding CSS to HTML

There are three main ways to add CSS to your HTML document:

  1. Inline CSS: Directly in the HTML element.
   <h1 style="color: blue;">Hello, World!</h1>
  1. Internal CSS: Within a <style> tag in the <head> section of your HTML document.
   <head>
     <style>
       h1 {
         color: blue;
       }
     </style>
   </head>
  1. External CSS: Linking to an external CSS file from your HTML document.
   <head>
     <link rel="stylesheet" href="styles.css">
   </head>

styles.css:

   h1 {
     color: blue;
   }

Practice Exercise

  • Create an HTML file with a few different elements like <h1>, <p>, and <div>.
  • Apply different colors, font sizes, and background colors to these elements using all three methods: inline, internal, and external CSS.
  • Experiment with different properties to see how they affect the appearance of your elements.

Next Up: In the next lecture, we’ll dive into Selectors and Properties and learn how to target and style different elements on your webpage. Stay tuned!

This first lecture introduces the basics of CSS, explaining what it is, why it's important, and how to write simple CSS rules. The example provided is easy to follow, and the exercise encourages students to practice and explore on their own.

follow me on LinkedIn

Ridoy Hasan


This content originally appeared on DEV Community and was authored by Ridoy Hasan


Print Share Comment Cite Upload Translate Updates
APA

Ridoy Hasan | Sciencx (2024-08-20T19:09:18+00:00) Introduction to CSS. Retrieved from https://www.scien.cx/2024/08/20/introduction-to-css/

MLA
" » Introduction to CSS." Ridoy Hasan | Sciencx - Tuesday August 20, 2024, https://www.scien.cx/2024/08/20/introduction-to-css/
HARVARD
Ridoy Hasan | Sciencx Tuesday August 20, 2024 » Introduction to CSS., viewed ,<https://www.scien.cx/2024/08/20/introduction-to-css/>
VANCOUVER
Ridoy Hasan | Sciencx - » Introduction to CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/20/introduction-to-css/
CHICAGO
" » Introduction to CSS." Ridoy Hasan | Sciencx - Accessed . https://www.scien.cx/2024/08/20/introduction-to-css/
IEEE
" » Introduction to CSS." Ridoy Hasan | Sciencx [Online]. Available: https://www.scien.cx/2024/08/20/introduction-to-css/. [Accessed: ]
rf:citation
» Introduction to CSS | Ridoy Hasan | Sciencx | https://www.scien.cx/2024/08/20/introduction-to-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.