CSS (Cascading Style Sheets) is a styling language used to control the presentation of documents written in HTML, XML, and similar markup languages. It defines how elements appear on screen or in other media, enhancing the overall look and user experience of a webpage.
Allows developers to style and layout web pages with colors, fonts, spacing, and positioning.
Separates content from design, making webpages easier to maintain and more visually consistent.
CSS Basics
Cascading Style Sheet(CSS) is used to set the style in web pages that contain HTML elements, here we will see in how many ways we can add CSS for our HTML, there three different ways to do so one by one we will see those procedure.
External CSS:External CSS contains a separate CSS file with a .css extension which contains only style property with the help of tag attributes.
selector{ property1: value1; property2: value2; }
Include external CSS file: The external CSS file is linked to the HTML document using a link tag.
The CSS border properties allow you to specify how the border of the box representing an element should look.
Border Color: Applies color to edges because Border Color sets border color when a border style exists.
Border Style: Creates visual patterns as Border Style defines solid, dotted, dashed, or decorative border types.
Border Width: Adjusts edge thickness because Border Width controls how thick or thin a border appears
Classification Properties
The CSS classification properties allow you to specify how and where an element is displayed.
Display: Controls page rendering because Display sets an element as inline, block, flex, grid, or none.
Float: Manages content flow as Float lets elements shift left or right allowing text to wrap.
Position: Defines placement because Position sets static, relative, absolute, fixed, or sticky behavior.
Clear: Regulates layout flow as Clear blocks floating elements on chosen sides.
Visibility: Handles element presence because Visibility decides if an element is visible, hidden, or collapsed while keeping space.
Cursor: Customizes pointer style as Cursor changes mouse appearance to default, pointer, help, or crosshair.
CSS Functions
CSS has a range of inbuilt functions. These are used as a value for various CSS properties. Some of the CSS functions can be nested as well. It ranges from simple color functions to mathematical, shape, color, transform, gradient, and animations functions. Some of the key functions are:
attr(): Enables dynamic styling because attr() retrieves a selected elementโs attribute value.
calc(): Allows flexible sizing as calc() performs mathematical calculations directly in CSS.
max(): Picks the largest option because max() returns the highest value from comma-separated numbers.
url(): Loads external resources as url() fetches images, fonts, or files using a provided link.
var(): Makes styling reusable because var() inserts values of custom CSS properties.
Media Queries
The CSS Media Query is used to make the web page more responsive according to the different screens or media types. Media queries include a block of CSS only if a certain expression is true.
Syntax:
@media not | only mediatype and (expression) { // Code content
All: Used for all types of media devices, applying styles universally.
Print: Used when printing a document, allowing styles optimized for printed output.
Screen: Used for digital displays such as computer screens, tablets, and smartphones.
Speech: Used for screen readers that read content aloud, enabling accessibility-focused styling.