HTML CSS

HTML Colors

HTML Colors

Learn how to use colors in HTML to style your web pages and make them visually appealing!

HTML Styles - CSS

CSS stands for Cascading Style Sheets.

CSS makes web development easier by controlling the layout of multiple web pages simultaneously.

CSS primarily deals with:

  • Styles and Colors
  • Manipulating Text
  • Decorating Boxes
  • Layouts and Positioning
  • Responsive Design

What is CSS?

Cascading Style Sheets (CSS) are used to format the layout of a webpage, giving developers control over various aspects like color, font, size of text, spacing, positioning of elements, background images, and much more!

The term "cascading" implies that styles applied to a parent element will also apply to its children unless specified otherwise.

Using CSS

CSS can be incorporated into HTML documents in three ways:

  • Inline: By using the style attribute inside HTML elements.
  • Internal: By using a <style> element in the <head> section.
  • External: By using a <link> element to reference an external CSS file.

While the most common method is to use external CSS files, we'll focus on inline and internal styles for demonstration purposes in this tutorial.

Inline CSS

Inline CSS is used to apply unique styles to individual HTML elements by using the style attribute.

<h1 style="color: blue;">A Blue Heading</h1>
<p style="color: red;">A red paragraph.</p>

Internal CSS

Internal CSS is used to define styles for a single HTML page within the <head> section using the <style> element.

<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1   {color: blue;}
p    {color: red;}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>

External CSS

External CSS is employed to define styles for multiple HTML pages by linking an external CSS file using the <link> element.

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>

CSS Colors, Fonts, and Sizes

CSS properties such as color, font-family, and font-size are commonly used to style text.

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  color: blue;
  font-family: verdana;
  font-size: 300%;
}
p {
  color: red;
  font-family: courier;
  font-size: 160%;
}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>

CSS Border

The border property in CSS is used to define borders around HTML elements.

p {
  border: 2px solid powderblue;
}

CSS Padding

CSS padding property is utilized to create space between the text and the border of an element.

p {
  border: 2px solid powderblue;
  padding: 30px;
}

CSS Margin

The margin property in CSS determines the space outside the border of an element.

p {
  border: 2px solid powderblue;
  margin: 50px;
}

Link to External CSS

External CSS files can be referenced with a full URL or a path relative to the current webpage.

<link rel="stylesheet" href="https://www.w3schools.com/html/styles.css">

Layouts and Positioning

CSS provides various techniques for creating layouts and positioning elements on a webpage. Flexbox and Grid are popular methods for creating responsive layouts.

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

Responsive Design

Responsive design ensures that web pages render well on a variety of devices and window or screen sizes. Media queries are commonly used to apply different styles based on the device characteristics.

@media only screen and (max-width: 600px) {
  body {
    font-size: 14px;
  }
}

Summary

Use inline CSS for individual element styling.

Employ internal CSS within the <head> section for single-page styling.

Utilize external CSS files for styling across multiple web pages.

CSS properties such as color, font-family, font-size, border, padding, and margin are commonly used for styling.

CSS provides techniques for layouts, positioning, and responsive design to create visually appealing and functional web pages.

This modified content provides an overview of CSS along with examples and explanations for different styling techniques.

Practice Your CSS Skills

Enhance your web design skills with HTML and CSS. Let your creativity shine and build captivating web experiences!

© 2023 Your Website. All rights reserved.