QAPage – Software Testing Jobs, QA Resources & Careers

QAPage Navigation & Directory
Type any keyword to search live pages, tools, or press Search to query site-wide.

CSS Full Notes PDF: Complete Guide for Software Testers

CSS Full Notes PDF (Quality Assurance Testers)

Complete CSS Guide for Beginners and Experienced Testers
These notes explain CSS in simple, human-friendly language, with practical examples, real-time testing scenarios, and interview questions. The focus is on what a QA tester needs to understand when testing websites and web applications manually or through automation tools such as Selenium and Playwright.

Module 1: Introduction to CSS

1. What is CSS?

CSS stands for Cascading Style Sheets. It is used to control how a website looks on the screen.
HTML creates the structure of a webpage, while CSS makes that structure look attractive and organized.
For example, HTML creates a login button. CSS decides its background color, text color, width, height, border, and position.

Example: Login button

Without CSS
Login
With CSS
Login
The purpose of CSS is to improve the appearance, layout, readability, and responsiveness of a webpage.

2. Why should a QA tester learn CSS?

A QA tester does not always need to write CSS from scratch. However, understanding CSS makes it easier to identify UI defects, inspect webpage elements, and write reliable automation scripts.
Important uses of CSS knowledge in QA:
  • Check whether text, buttons, images, and forms look correct.
  • Identify alignment, spacing, color, and font issues.
  • Verify that a webpage works on mobile, tablet, and desktop.
  • Find elements using CSS selectors in Selenium or Playwright.
  • Identify hidden, disabled, overlapping, or incorrectly positioned elements.
  • Inspect hover effects, error messages, responsive layouts, and navigation menus.
  • Debug UI issues using browser Developer Tools.
Real-time example: Suppose the Submit button is visible on a desktop but disappears on mobile. A QA tester can inspect the element’s CSS properties and check whether a media query, display: none, or an incorrect layout rule is causing the problem.

3. Difference between HTML, CSS, and JavaScript

Technology
Main purpose
Example
HTML
Creates webpage structure
Login form, button, heading
CSS
Controls appearance and layout
Colors, spacing, alignment
JavaScript
Adds behavior and interaction
Form validation, dropdown actions
A simple way to remember:
  • HTML = Structure
  • CSS = Appearance
  • JavaScript = Behavior

4. How CSS works

A CSS rule generally contains three parts:
h1 {  color: blue;  font-size: 32px;}
  • h1 is the selector. It identifies which HTML element to style.
  • color and font-size are properties.
  • blue and 32px are values.
The browser reads the CSS rules and applies the relevant styles to the webpage.

Types of CSS

There are three common ways to apply CSS to HTML.

1. Inline CSS

Inline CSS is written directly inside an HTML element using the style attribute.
<button style="background-color: blue; color: white;">  Login</button>
Advantages
  • Useful for a quick, individual style change.
  • The style is written directly on the element.
Disadvantages
  • Difficult to maintain when many elements need the same style.
  • Can make HTML harder to read.
  • Can be difficult to override because inline styles generally have higher priority than normal stylesheet rules.
QA example: Verify whether one button has a different color from other buttons because an inline style overrides the shared stylesheet.

2. Internal CSS

Internal CSS is written inside a style element in the HTML document, usually within the head section.
<head>  <style>    h1 {      color: green;    }    button {      padding: 10px 20px;    }  </style></head>
It is useful when styles are needed for a single webpage, but it can become difficult to maintain across a large website.

3. External CSS

External CSS is stored in a separate .css file and connected to the HTML page.
HTML:
<link rel="stylesheet" href="style.css">
CSS file (style.css):
h1 {  color: green;}button {  padding: 10px 20px;}
Advantages
  • The same stylesheet can be reused across multiple pages.
  • Easier to maintain and update.
  • Keeps the HTML structure separate from presentation.
QA testing points
  • Check whether the stylesheet loads successfully.
  • Verify that the correct styles are applied on all relevant pages.
  • Check for missing CSS files, broken paths, and unexpected style overrides.

 CSS Selectors

1. What is a CSS selector?

A CSS selector tells the browser which HTML element should receive a particular style.
For QA testers, selectors are especially important because they are used to locate elements during UI automation.

2. Basic CSS selectors

Element selector
Selects all elements with a particular HTML tag.
p {  color: black;}
This applies the style to all paragraph elements.
ID selector
Selects an element using its unique ID. An ID selector starts with #.
<input id="username" type="text">
#username {  border: 1px solid blue;}
In automation:
// Playwrightpage.locator("#username");
Class selector
Selects elements with a particular class. A class selector starts with a dot.
<button class="login-btn">Login</button>
.login-btn {  background-color: blue;}
In automation:
page.locator(".login-btn");
Universal selector
Selects all elements.
* {  box-sizing: border-box;}
This is commonly used to make element sizing easier to manage.
Grouping selector
Applies the same styles to multiple selectors.
h1, h2, p {  font-family: Arial, sans-serif;}

3. Attribute selectors

Attribute selectors identify elements based on their HTML attributes or attribute values.
Selector
Meaning
input[type="text"]
Text input fields
input[type="password"]
Password fields
input[required]
Inputs with a required attribute
a[target="_blank"]
Links that open in a new browsing context
button[disabled]
Buttons with a disabled attribute
input[placeholder]
Inputs that have a placeholder attribute
Example:
<input type="email" placeholder="Enter email">
input[type="email"] {  border: 1px solid gray;}
QA use case: You can use an attribute selector to locate all password inputs or all disabled buttons during testing.

4. CSS combinators

Combinators describe the relationship between elements.
Selector
Meaning
Example
div p
Any paragraph inside a div, at any depth
div p
div > p
A paragraph that is a direct child of a div
div > p
h2 + p
The first paragraph immediately following an h2
h2 + p
h2 ~ p
Paragraph siblings that follow an h2
h2 ~ p
Example HTML:
<div class="form">  <p>Enter your details</p>  <section>    <p>Additional information</p>  </section></div>
  • .form > p matches the first paragraph.
  • .form p matches both paragraphs.
Interview tip: The main difference between the descendant selector and the child selector is that a descendant can appear at any depth, while a child must be directly inside its parent.

5. Pseudo-classes

A pseudo-class selects an element based on its state or position.
Pseudo-class
Meaning
:hover
Pointer is over the element
:focus
Element has keyboard or input focus
:active
Element is being activated
:first-child
Element is the first child of its parent
:last-child
Element is the last child of its parent
:nth-child(2)
Element is the second child
:checked
Checkbox or radio input is checked
:disabled
Form control is disabled
:valid
Form control satisfies its validation constraints
:invalid
Form control fails its validation constraints
Example:
button:hover {  background-color: darkblue;}input:focus {  border-color: blue;}input:invalid {  border-color: red;}
QA scenario: When a user enters an invalid email address, verify whether the input shows the expected error styling. Also confirm that the actual validation behavior works; a red border alone does not prove validation is correct.

6. Pseudo-elements

Pseudo-elements style a specific part of an element or create generated content.
p::first-letter {  font-size: 24px;}.required::after {  content: " *";  color: red;}
Common examples:
  • ::before — inserts generated content before an element’s content.
  • ::after — inserts generated content after an element’s content.
  • ::first-letter — styles the first letter.
  • ::first-line — styles the first line.
  • ::placeholder — styles placeholder text.
QA testers should verify that decorative symbols, required-field indicators, and placeholder styles are displayed correctly and do not cause accessibility or usability problems.

7. CSS specificity

Specificity helps determine which CSS rule wins when multiple rules target the same element and affect the same property.
Consider:
<p id="message" class="warning">Invalid password</p>
p {  color: black;}.warning {  color: orange;}#message {  color: red;}
The text will normally appear red because the ID selector has higher specificity than the class and element selectors.
A simplified specificity order is:
  1. Inline styles
  2. ID selectors
  3. Class, attribute, and pseudo-class selectors
  4. Element and pseudo-element selectors
The universal selector has no specificity weight. Combinators do not add specificity themselves.
Important: Specificity is not the only factor. The cascade also considers importance, origin, cascade layers, and source order. For example, an applicable !important declaration can override an ordinary declaration.
.warning {  color: orange !important;}
Use !important sparingly because it can make styles harder to maintain.
Real-time QA scenario: A button should be green, but it appears red. Inspect its computed styles and determine which CSS rule is winning. Check its selector, specificity, importance, and whether another stylesheet overrides it.

8. CSS selectors for automation testing

Suppose a login page contains:
<input id="email" type="email"><input id="password" type="password"><button class="submit-btn">Login</button>
Playwright examples:
page.locator("#email");page.locator("#password");page.locator(".submit-btn");page.locator('input[type="password"]');
Selenium with Java:
driver.findElement(By.cssSelector("#email"));
driver.findElement(By.cssSelector("#password"));
driver.findElement(By.cssSelector(".submit-btn"));
driver.findElement(By.cssSelector("input[type='password']"));
Prefer stable IDs or dedicated test attributes when available. For user-facing controls, Playwright’s role and label locators are often more resilient and accessible than CSS selectors.

CSS Colors, Backgrounds, and Borders

1. Color properties

CSS supports several ways to specify colors.
.heading 
{ 
 color: red;
}
.success 
{ 
 color: #008000;
}
.info
 { 
 color: rgb(0, 0, 255);
}
.overlay
 { 
 background-color: rgba(0, 0, 0, 0.5);}
Common formats:
  • Named colors: red, blue, black.
  • HEX: #ff0000.
  • RGB: rgb(255, 0, 0).
  • RGBA: rgba(255, 0, 0, 0.5).
  • HSL: hsl(0, 100%, 50%).
RGBA includes an alpha value for transparency.

2. Background properties

.card 
{ 
 background-color: white; 
 background-image: url("banner.jpg"); 
 background-repeat: no-repeat; 
 background-position: center; 
 background-size: cover;
}
Important properties:
Property
Purpose
background-color
Sets background color
background-image
Sets a background image
background-repeat
Controls image repetition
background-position
Sets image position
background-size
Controls image sizing
background-attachment
Controls how the background behaves during scrolling

3. Border properties

input {  border: 1px solid gray;  border-radius: 6px;}
  • border-width: thickness.
  • border-style: solid, dashed, dotted, and others.
  • border-color: border color.
  • border-radius: rounds corners.

QA testing checklist

  • Verify that the correct color appears in each state.
  • Check that text is readable against the background.
  • Confirm that buttons, cards, and input fields have the expected borders.
  • Check whether background images load and crop correctly.
  • Test error, success, hover, focus, and disabled states.
  • Verify color contrast and do not rely on color alone to communicate an error or success.
Example defect: The error message is displayed in light red on a white background and is difficult to read. Record the actual color, expected color or contrast requirement, browser, device, and screenshot.

Text and Font Properties

CSS typography controls how text looks and how easily users can read it.

1. Font properties

body {  font-family: Arial, sans-serif;  font-size: 16px;  font-weight: 400;  font-style: normal;}
Property
Purpose
font-family
Selects the typeface
font-size
Sets text size
font-weight
Controls thickness, such as 400 or 700
font-style
Sets normal or italic text
line-height
Controls the height of each line
letter-spacing
Adjusts spacing between characters
word-spacing
Adjusts spacing between words

2. Text alignment and decoration

h1 {  text-align: center;  text-decoration: none;}a {  text-decoration: underline;}p {  text-transform: none;  overflow-wrap: anywhere;}
Important properties include:
  • text-align: left, right, center, or justify.
  • text-decoration: underline, overline, or line-through.
  • text-transform: uppercase, lowercase, or capitalize.
  • text-indent: indentation of the first line.
  • white-space: controls how whitespace and line breaks are handled.
  • overflow-wrap: helps long words or strings wrap instead of overflowing.

3. CSS units used in text styling

Unit
Meaning
Example
px
CSS pixel
font-size: 16px
em
Relative to the relevant element’s font size
font-size: 1.2em
rem
Relative to the root element’s font size
font-size: 1rem
%
Percentage-based value where supported
width: 100%
vw
Percentage of viewport width
font-size: 2vw
QA scenario: A heading fits on desktop but gets cut off on mobile. Check its font size, available width, line height, white-space rules, and responsive styles.

4. Typography testing checklist

  • Confirm that the correct font loads.
  • Check font size, weight, color, and alignment.
  • Verify that headings and paragraphs wrap properly.
  • Check long words, URLs, and large numbers.
  • Test text at browser zoom levels and on small screens.
  • Confirm that buttons and form labels remain readable.
  • Check that translated or longer text does not overlap nearby elements.

The CSS Box Model

The box model is one of the most important CSS concepts for UI testing.
Every ordinary block-level element is laid out using a box consisting of content, padding, border, and margin.
Margin — space outside the border
Border
Padding — space inside the border
Content
Conceptual illustration of the CSS box model. Margin is outside the border; padding is between the content and border.

1. Content

The content is the actual text, image, or other material inside the element.
.card {  width: 300px;  height: 150px;}
By default, with content-box, the specified width and height refer to the content area.

2. Padding

Padding is the space between the content and its border.
.card {  padding: 20px;}
You can control individual sides:
.card {  padding-top: 10px; 
 padding-right: 20px;  
padding-bottom: 10px; 
 padding-left: 20px;
}

3. Border

The border surrounds the padding and content.
.card {  border: 2px solid black;}

4. Margin

Margin creates space outside the element’s border.
.card {  margin: 20px;}
Example:
.card {  margin: 10px;  padding: 20px;  border: 2px solid black;}
With content-box and a declared width of 300px, the rendered border-box width is:
\(300 + 20 + 4 = 324\text{px}\)
The left and right padding add 40px in total, and the two borders add 4px.

5. The box-sizing property

* {  box-sizing: border-box;}
With border-box, the declared width includes content, padding, and border. This often makes responsive layouts easier to manage.
QA scenario: A card should be 300px wide, but it occupies 324px and pushes other content out of alignment. Check its box-sizing, width, padding, and border values.

6. Margin vs padding

Margin
Padding
Space outside the border
Space inside the border
Separates elements from each other
Separates content from its border
Background does not fill the margin area
Background generally fills the padding area
Can collapse vertically in some block layouts
Does not collapse

7. Box model testing

Verify:
  • The width and height match the design.
  • Cards have consistent internal spacing.
  • Buttons have enough padding for their labels.
  • Form fields align correctly.
  • Margins do not create unwanted gaps or overlap.
  • Elements do not overflow their containers.
  • Layouts remain correct when text length changes.

 CSS Display Properties

The display property determines how an element participates in layout.

1. display: block

A block element normally starts on a new line and occupies the available width of its containing block.
div {  display: block;}
Examples include many div, p, and heading elements.

2. display: inline

An inline element flows within a line of text.
span {  display: inline;}
Its width and height generally do not behave like those of a block box. Some sizing properties do not affect ordinary non-replaced inline elements in the same way they affect block elements.

3. display: inline-block

This allows an element to flow inline while accepting explicit width and height.
button {  display: inline-block;  width: 120px;  height: 40px;}

4. display: none

The element is not displayed and does not occupy layout space.
.popup {  display: none;}

5. visibility: hidden

The element is invisible but still occupies its layout space.
.popup {  visibility: hidden;}

6. opacity: 0

The element becomes fully transparent but generally retains its layout space. It can still receive pointer or keyboard interaction depending on its other styles and behavior.
.popup {  opacity: 0;}

Important QA comparison

Property
Visible?
Keeps layout space?
display: none
No
No
visibility: hidden
No
Yes
opacity: 0
No, fully transparent
Yes
Real-time scenario: A menu item is missing. Inspect its computed display, visibility, and opacity values. Also check whether a parent element is hidden.
For automation testers, remember that a CSS rule alone does not determine whether an element is considered visible by every automation tool. The tool’s visibility rules, element dimensions, and ancestor states also matter.

 CSS Positioning and Z-Index

Positioning controls where elements appear on the webpage.

1. Static positioning

.card {  position: static;}
This is the default positioning mode. The element follows the normal document flow, and top, right, bottom, and left do not reposition it.

2. Relative positioning

.card {  position: relative;  top: 10px;  left: 20px;}
The element is shifted from its normal position, while its original layout space is generally retained.

3. Absolute positioning

.parent {  position: relative;}.close-btn {  position: absolute;  top: 10px;  right: 10px;}
An absolutely positioned element is removed from normal flow and positioned relative to its containing block, which is often established by a positioned ancestor.

4. Fixed positioning

.help-btn
 { 
 position: fixed;  
right: 20px; 
 bottom: 20px;
}
A fixed element is generally positioned relative to the viewport and stays in place while the page scrolls, although certain ancestor properties can change its containing block.

5. Sticky positioning

.header
 { 
 position: sticky; 
 top: 0;
}
A sticky element behaves like a normally positioned element until it reaches its specified scroll threshold within its scrolling container.

6. Z-index

z-index helps control the stacking order of overlapping elements.
.modal
{ 
 position: fixed;  
z-index: 1000;
}
.header 
{  
position: relative;  
z-index: 10;
}
A higher z-index does not always mean an element appears above every other element. Stacking contexts can limit the effect.

QA test scenarios

  • Check whether a sticky header hides page content.
  • Verify that modal dialogs appear above the page.
  • Check whether dropdowns are cut off or covered by other elements.
  • Verify that a fixed help button does not cover the Submit button.
  • Check whether close buttons stay inside their intended containers.
  • Scroll the page to test sticky and fixed elements.
Example defect: The modal opens, but the page header appears over it. Inspect stacking contexts, z-index, positioning, and ancestor properties.

 Flexbox

Flexbox is a CSS layout system used to arrange elements in a row or column. It is widely used for navigation bars, button groups, forms, cards, and page headers.

1. Flex container and flex items

The parent element becomes a flex container when you apply display: flex. Its direct children become flex items.
<div class="container"> 
 <div>Home</div> 
 <div>About</div>  
<div>Contact</div></div>
.container {  display: flex;  gap: 20px;}
The items will normally appear in a row.

2. Important Flexbox properties

Property
Purpose
display: flex
Creates a flex container
flex-direction
Sets the main direction
justify-content
Aligns items along the main axis
align-items
Aligns items along the cross axis
flex-wrap
Controls whether items can move to another line
gap
Adds space between items
flex-grow
Controls how items share extra space
flex-shrink
Controls how items shrink when space is limited
flex-basis
Sets the initial main size of an item
align-self
Overrides cross-axis alignment for one item

3. Flex direction

.container {  display: flex;  flex-direction: row;}
Common values:
  • row: left to right in the usual horizontal writing mode.
  • row-reverse: reverse row direction.
  • column: vertical direction.
  • column-reverse: reverse column direction.

4. Justify content

.container {  display: flex;  justify-content: space-between;}
Common values:
  • flex-start
  • flex-end
  • center
  • space-between
  • space-around
  • space-evenly
This property aligns items along the main axis, which changes depending on flex-direction.

5. Align items

.container {  display: flex;  align-items: center;}
Common values include stretch, flex-start, flex-end, center, and baseline.

6. Flex wrap

.cards {  display: flex;  flex-wrap: wrap;  gap: 16px;}
When the row does not have enough space, items can move onto another line.

7. Flex grow and shrink

.left {  flex-grow: 1;}.right {  flex-grow: 2;}
The second item receives twice the share of the available positive free space under otherwise comparable conditions.
.item {  flex-shrink: 1;}
An item with flex-shrink: 1 can shrink when the layout is short of space, subject to its sizing constraints.

Real-time QA example

A navigation bar displays Home, About, Services, and Contact. On desktop, everything looks correct, but on mobile, Contact is pushed outside the screen.
Check:
  1. Is display: flex applied to the correct parent?
  2. Is flex-wrap set appropriately?
  3. Is the gap too large for the available width?
  4. Are the items allowed to shrink?
  5. Is the parent width constrained?
  6. Is a media query changing the layout?

Flexbox interview questions

Q1. What is Flexbox?
Flexbox is a CSS layout method for arranging items along a main axis and aligning them along a cross axis.
Q2. What is the difference between justify-content and align-items?
justify-content aligns items along the main axis. align-items aligns items along the cross axis.
Q3. What does flex-wrap: wrap do?
It allows flex items to move onto another line when there is insufficient space.

CSS Grid

CSS Grid is a layout system designed to arrange content in rows and columns. It is particularly useful for dashboards, product listings, galleries, and card-based layouts.

1. Creating a grid

<div class="grid">  <div>Card 1</div>  <div>Card 2</div>  <div>Card 3</div>  <div>Card 4</div></div>
.grid {  display: grid;  grid-template-columns: repeat(2, 1fr);  gap: 20px;}
This creates two equal-width columns.

2. Important Grid properties

Property
Purpose
display: grid
Creates a grid container
grid-template-columns
Defines columns
grid-template-rows
Defines rows
gap
Adds space between rows and columns
row-gap
Controls row spacing
column-gap
Controls column spacing
grid-column
Controls which columns an item occupies
grid-row
Controls which rows an item occupies
grid-template-areas
Defines named layout areas
justify-items
Aligns items within their grid areas horizontally in the usual writing mode
align-items
Aligns items within their grid areas on the block axis

3. The fr unit

The fr unit represents a share of the available space in a grid container.
.grid {  display: grid;  grid-template-columns: 1fr 2fr;}
The second column receives twice the share of available space allocated by these flexible tracks, subject to track sizing constraints.

4. Responsive grid using minmax()

.products {  display: grid;  grid-template-columns: repeat(3, minmax(0, 1fr));  gap: 16px;}
Here, minmax(0, 1fr) allows each column to shrink to zero when necessary instead of preserving a larger automatic minimum size.
For a flexible number of columns:
.products {  display: grid;  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));  gap: 16px;}
The browser creates as many columns as can fit based on the minimum track size and available width.

5. Flexbox vs Grid

Flexbox
Grid
Primarily one-dimensional
Two-dimensional
Arranges items along a row or column
Controls rows and columns together
Useful for navigation bars and button groups
Useful for dashboards and card layouts
Items can wrap into additional lines
Items are arranged within a defined grid structure
Both systems can be used together.

QA testing scenario

A product page displays three cards per row on desktop, two on tablets, and one on mobile.
Verify:
  • The number of columns at each viewport size.
  • Consistent card gaps and alignment.
  • No overlapping or clipped content.
  • Long titles do not break the grid.
  • Images maintain the expected proportions.
  • Cards remain readable when text or prices change.

 Responsive Web Design and Media Queries

Responsive web design makes a website adapt to different screen sizes and devices.
A page should remain usable on desktops, laptops, tablets, and mobile phones without unnecessary horizontal scrolling or overlapping content.

1. What is a media query?

A media query applies CSS only when certain conditions are met, such as a viewport-width range.
@media (max-width: 600px)
 { 
 .container
 {   
 padding: 12px;  
}  
h1
 { 
   font-size: 24px; 
 }}
When the viewport is 600 CSS pixels wide or less, these rules apply.

2. Example: Responsive layout

.cards {  display: grid; 
 grid-template-columns: repeat(3, minmax(0, 1fr)); 
 gap: 20px;}@media (max-width: 900px)
{
  .cards 
{   
 grid-template-columns: repeat(2, minmax(0, 1fr)); 
 }}
@media (max-width: 600px) 
{  
.cards
 {  
  grid-template-columns: 1fr; 
 }}
Expected layout:
  • Large screens: three columns.
  • Medium screens: two columns.
  • Small screens: one column.
These breakpoints are examples, not universal standards. They should be selected based on where the content stops fitting comfortably.

3. Viewport meta tag

A responsive HTML page normally includes:
<meta name="viewport" content="width=device-width, initial-scale=1">
Without an appropriate viewport configuration, mobile browsers may use a wider virtual layout viewport and scale the page, affecting responsive behavior.

4. Common responsive testing breakpoints

Device category
Example viewport width
Small mobile
320px
Common mobile
375px
Large mobile
430px
Tablet
768px
Small laptop
1024px
Desktop
1366px
Large desktop
1920px
These are test examples, not fixed device specifications. Actual devices may have different viewport sizes, browser toolbars, pixel ratios, and orientations.

5. Responsive testing checklist

  • Check horizontal scrolling at narrow widths.
  • Verify that the navigation menu works on mobile.
  • Check that buttons remain visible and tappable.
  • Confirm that text does not overlap images or other text.
  • Verify that forms fit the screen.
  • Test portrait and landscape orientation.
  • Check modal dialogs and dropdowns.
  • Verify that images scale without distortion.
  • Test at intermediate widths, not only predefined breakpoints.
  • Check browser zoom and enlarged text.
  • Confirm that sticky headers and footers do not hide important content.

6. How to test responsive layouts in Chrome

  1. Open the website in Google Chrome.
  2. Press F12 or Ctrl + Shift + I.
  3. Click the device toolbar icon, or press Ctrl + Shift + M.
  4. Select a device profile or enter a custom viewport width and height.
  5. Test the page at different widths.
  6. Check portrait and landscape orientation.
  7. Inspect any overlapping, missing, or clipped elements.
  8. Compare the result with the expected design.
Important: Chrome’s device toolbar simulates many viewport and device conditions, but it does not replace testing on real devices and browsers when those are part of the test requirements.

CSS Overflow

Overflow controls what happens when content is larger than its container.

1. Main overflow values

.container {  overflow: visible;}
Value
Behavior
visible
Content can extend outside the box
hidden
Excess content is clipped
scroll
Scrollbars are provided for the relevant overflow axes
auto
The browser provides scrolling when needed
clip
Content is clipped without creating a scroll container
The exact scrollbar appearance depends on the browser and operating system.

2. Horizontal and vertical overflow

.container {  overflow-x: auto;  overflow-y: hidden;}
  • overflow-x controls horizontal overflow.
  • overflow-y controls vertical overflow.

3. Text overflow

A common way to show an ellipsis when a single line of text is too long is:
.title {  white-space: nowrap;  overflow: hidden;  text-overflow: ellipsis;}
The element needs an appropriate width constraint for the ellipsis to appear.

QA scenarios

  • A long username extends outside a profile card.
  • A table’s last columns are inaccessible on mobile.
  • A button label is cut off.
  • A dropdown menu is clipped by its parent.
  • A modal’s content cannot be scrolled.
  • A long URL causes horizontal scrolling across the entire page.
How to investigate: Inspect the element’s dimensions, overflow, white-space, width constraints, and parent containers. Decide whether clipping or scrolling is expected for that component.

CSS Transitions, Transforms, and Animations

CSS can create visual effects when a user interacts with an element or when an animation runs.

1. Transitions

A transition makes a change between property values happen gradually.
button { 
 background-color: blue; 
 transition: background-color 0.3s ease;
}
button:hover 
{ 
 background-color: darkblue;
}
The button’s background color changes smoothly when the pointer hovers over it.
Common transition properties:
  • transition-property
  • transition-duration
  • transition-timing-function
  • transition-delay

2. Transforms

Transforms change an element’s visual position, size, rotation, or skew.
.card:hover {  transform: scale(1.05);}
Other examples:
.box {  transform: translateX(10px);}.image {  transform: rotate(5deg);}
A transform changes the visual rendering but does not normally change the element’s original layout space.

3. Animations

Animations can use keyframes to define intermediate styles.
@keyframes fadeIn {  from {    opacity: 0;  }  to {    opacity: 1;  }}.message {  animation: fadeIn 0.5s ease;}
Important properties include animation-name, animation-duration, animation-delay, animation-iteration-count, and animation-direction.

4. Reduced motion

Some users prefer less animation because of motion sensitivity.
@media (prefers-reduced-motion: reduce) {  .animated-element {    animation: none;    transition: none;  }}
A real implementation should apply reduced-motion behavior consistently to the relevant effects.

QA testing checklist

  • Verify that hover effects appear only when expected.
  • Check transitions for sudden jumps or unwanted delays.
  • Confirm that animations do not hide important content.
  • Check for overlapping elements during movement.
  • Verify that animations do not block clicks or keyboard interaction.
  • Test the reduced-motion preference.
  • Confirm that animation timing does not interfere with automated tests.
Automation tip: Avoid relying on arbitrary fixed sleeps for animation completion. Use meaningful conditions, suitable assertions, or animation-aware testing strategies.

CSS Variables, Inheritance, and the Cascade

1. CSS custom properties (variables)

Custom properties let developers reuse values throughout a stylesheet.
:root 
{ 
 --primary-color: #2563eb; 
 --text-color: #222222; 
 --spacing: 16px;
}
button 
{ 
 background-color: var(--primary-color);
}
p 
{ 
 color: var(--text-color); 
 margin-bottom: var(--spacing);
}
Advantages:
  • Shared colors and spacing are easier to maintain.
  • Themes can be changed centrally.
  • Repeated values can be kept consistent.
QA scenario: The brand color changes, but one button still uses the old color. Check whether the component uses the shared custom property or a hardcoded value.

2. Inheritance

Some CSS properties can pass from a parent to its descendants.
body 
{ 
color: #222; 
 font-family: Arial, sans-serif;
}
Text elements commonly inherit the font family and color unless another rule changes them.
However, many layout and box-model properties, such as margin, padding, and border, do not inherit by default.

3. The cascade

When multiple declarations apply to an element, the browser decides which declaration wins based on the CSS cascade.
The important factors include:
  • Origin and importance.
  • Cascade layers.
  • Selector specificity.
  • Scoping proximity where applicable.
  • Source order when the earlier factors are tied.
Real-time QA example: The website’s primary button should use the same blue color across several pages, but one page shows a different shade. Inspect its computed styles and trace the winning declaration to the relevant stylesheet or component.

 CSS Forms and Interactive States

Forms are important areas for UI testing because users rely on them to enter and submit information.

1. Styling form fields

input 
{ 
 width: 100%; 
 padding: 12px;
  border: 1px solid #cccccc;
  border-radius: 5px;
}

2. Focus state

input:focus 
{ 
 border-color: blue; 
 outline: 2px solid lightblue;
}
The focus state helps users identify which field is currently active.

3. Disabled state

button:disabled
 { 
 opacity: 0.5;
  cursor: not-allowed;
}
This changes the button’s appearance. It does not, by itself, implement all the business rules for disabling the button.

4. Validation states

input:invalid
 {
 border-color: red;
}
input:valid
 { 
 border-color: green;
}
These pseudo-classes reflect browser constraint validation. They should not be treated as a complete substitute for application-level validation requirements.

QA form scenarios

  1. Verify the default appearance of every input.
  2. Click each field and check its focus indicator.
  3. Enter valid and invalid values.
  4. Check required-field messages.
  5. Verify the disabled state of Submit where appropriate.
  6. Check checkbox and radio selection styles.
  7. Confirm that error messages are readable and positioned correctly.
  8. Test form layouts at different viewport sizes.
  9. Verify keyboard navigation.
  10. Confirm that visual validation matches actual form behavior.

CSS Tables, Images, and Cards

1. Tables

table 
{ 
 width: 100%; 
 border-collapse: collapse;
}
th,
td 
{  
padding: 12px;
border: 1px solid #dddddd;
text-align: left;
}
QA checks:
  • Column headings align correctly.
  • Rows do not overlap.
  • Text remains readable.
  • Wide tables are usable on mobile.
  • Borders and row spacing are consistent.
  • Long content does not break the layout.

2. Images

img {  max-width: 100%;  height: auto;}
This helps images fit within their containing block while preserving their intrinsic aspect ratio in normal circumstances.
For fixed image containers:
.thumbnail {  width: 300px;  height: 180px;  object-fit: cover;}
object-fit: cover fills the container and may crop parts of the image.
Common values:
  • cover: fills the container, potentially cropping.
  • contain: fits the whole image, potentially leaving empty space.
  • fill: stretches the image to the container dimensions and may distort it.
QA checks:
  • Images load correctly.
  • Images do not become distorted.
  • Cropping matches the design.
  • Alternative text is available where appropriate.
  • Image containers do not overflow.
  • Layout shifts caused by image loading are investigated when relevant.

3. Cards

.card {  padding: 20px;  border: 1px solid #dddddd;  border-radius: 8px;  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);}
Check consistent card heights where required, text wrapping, button alignment, shadows, and spacing.

CSS and Browser Developer Tools

Browser Developer Tools help QA testers investigate UI defects without changing the original source code.

1. Inspect an element

  1. Open the webpage in Chrome.
  2. Right-click the element.
  3. Select Inspect.
  4. Review the HTML in the Elements panel.
  5. Check the Styles panel for applied CSS rules.
  6. Review computed values in the Computed panel.
  7. Toggle CSS declarations to investigate the issue.

2. Inspect computed styles

Computed styles show the final resolved values for properties such as:
  • color
  • display
  • width
  • height
  • margin
  • padding
  • font-size
  • position
  • z-index
  • overflow
Use the box-model diagram in Developer Tools to inspect an element’s dimensions and spacing.

3. Test media queries

Use the device toolbar to change viewport dimensions and observe which responsive rules apply.
You can also inspect media queries directly in the Styles panel.

4. Check CSS loading problems

In Developer Tools:
  • Open the Network panel.
  • Reload the page.
  • Filter by CSS resources.
  • Check for failed stylesheet requests.
  • Inspect the Console for related errors.
A stylesheet may fail because of an incorrect URL, server response, access restriction, or deployment problem.

5. Temporary changes vs permanent fixes

Changes made in the browser’s Styles panel are generally temporary. They help you investigate the cause of a defect, but they do not permanently modify the website’s source code.
QA best practice: Record the original behavior, the steps to reproduce it, the browser and viewport, screenshots, and the relevant CSS evidence. Developers can then investigate the source code and implement a permanent fix.

CSS Selectors for Selenium and Playwright — Advanced Practice

A QA tester often needs to locate a specific button, input field, menu, or message. CSS selectors help identify elements based on their HTML structure and attributes.
Consider this HTML:
<form id="login-form">  
<input id="email" type="email" name="email"> 
 <input id="password" type="password" name="password"> 
 <button class="submit-btn" type="submit">Login</button> 
 <p class="error-message">Invalid credentials</p></form>

Common selectors with examples

Requirement
CSS selector
Find the email field
#email
Find the password field
#password
Find the login button
.submit-btn
Find all input elements
input
Find email inputs
input[type="email"]
Find elements inside the login form
#login-form input
Find direct children of a form
#login-form > input
Find the error message
.error-message
Find submit buttons
button[type="submit"]
Find required inputs
input[required]

Playwright example

const email = page.locator("#email");
const password = page.locator("#password");
const loginButton = page.locator(".submit-btn");
await email.fill("tester@example.com");
await password.fill("Test@123");
await loginButton.click();

Selenium with Java example

WebElement email =    driver.findElement(By.cssSelector("#email"));
WebElement password =    driver.findElement(By.cssSelector("#password"));
WebElement loginButton =    driver.findElement(By.cssSelector(".submit-btn"));
email.sendKeys("tester@example.com");
password.sendKeys("Test@123");
loginButton.click();
These are examples using a fictional test account. In actual projects, use test credentials and appropriate secret-management practices.

How to identify a good selector

A good selector should be:
  • Specific enough to locate the intended element.
  • Stable when the design changes.
  • Easy for other testers to understand.
  • Unlikely to match several unintended elements.
Avoid relying on deeply nested selectors such as:
body > div:nth-child(2) > div > form > button
This selector may break when developers add or rearrange containers.
Prefer stable selectors such as:
#login-form .submit-btn
Where possible, use a dedicated testing attribute:
<button data-testid="login-submit">Login</button>
page.getByTestId("login-submit");
For accessible applications, role- and label-based locators are often preferable:
page.getByRole("button", { name: "Login" });page.getByLabel("Email");
Interview question: Why do CSS selectors sometimes fail in automation?
Possible reasons include incorrect selectors, elements that have not loaded, duplicate matches, dynamically changing attributes, hidden elements, iframe boundaries, or changes in the page structure.

 CSS Accessibility Testing

CSS can affect whether a website is comfortable and accessible for people with different visual, motor, and cognitive needs.
QA testers should check both visual appearance and practical usability.

1. Color contrast

Text must have sufficient contrast against its background.
For WCAG 2.2 Level AA, the usual minimum contrast ratios are:
  • Normal text: 4.5:1.
  • Large text: 3:1.
  • Essential visual information for UI components and graphical objects: generally 3:1 against adjacent colors, where the criterion applies.
Do not assume that a color is accessible just because it looks readable on your own monitor.

2. Keyboard focus

button:focus-visible {  outline: 3px solid blue;  outline-offset: 2px;}
Test whether keyboard users can identify the currently focused control.
Check:
  • Links and buttons.
  • Form fields.
  • Dropdown menus.
  • Dialogs and popups.
  • Navigation menus.
  • Custom controls.

3. Avoid removing focus indicators

This rule can create an accessibility problem:
*:focus {  outline: none;}
Removing the outline without providing a suitable alternative can make keyboard navigation difficult.

4. Text resizing and zoom

Check whether the page remains usable when:
  • The browser is zoomed in.
  • Text is enlarged.
  • Content wraps onto additional lines.
  • Buttons have longer labels.
  • The user changes device orientation.

5. Do not rely only on color

For example, an invalid field should not communicate its error only through a red border. It should also have an understandable error message or another appropriate indicator.

6. Reduced motion

Verify that nonessential motion can be reduced when the user requests reduced motion, where relevant.

Accessibility testing scenario

A user navigates a registration form using only the keyboard. The focus indicator disappears on the Submit button.
Expected result: The focused button should have a clearly visible focus indicator that meets the applicable accessibility requirements.
Actual result: The button has no visible focus indicator.
Defect: Keyboard focus is not visually identifiable on the Submit button.

CSS Bug Reporting for QA

When a CSS issue is found, the defect report should explain what is wrong, where it happens, and how to reproduce it.

Example 1: Mobile layout issue

Bug report: Login button is cut off on mobile

Severity: Medium*
UI / Responsive
Environment: Chrome on a mobile viewport of 375 × 812 CSS pixels.
Precondition: The user has opened the login page.
Steps to reproduce:
  1. Open the login page.
  2. Set the viewport to 375 × 812.
  3. Scroll to the login form.
  4. Observe the Submit button.
Expected result: The Submit button is completely visible and usable within the intended layout.
Actual result: The right side of the button extends beyond the visible content area.
Possible areas to investigate: Fixed widths, container padding, flex sizing, grid track sizing, and horizontal overflow.
*Severity depends on the product’s impact and business requirements.

Example 2: Text overlap

Title: Heading overlaps the navigation menu on tablet view.
  • Steps: Open the homepage, set the viewport to a tablet-sized width, and inspect the header.
  • Expected: The heading and navigation should remain separate and readable.
  • Actual: The heading overlaps the navigation links.
  • Possible CSS causes: Incorrect positioning, fixed widths, insufficient flex space, or a missing breakpoint.

Example 3: Incorrect button state

Title: Disabled Submit button does not display the expected disabled styling.
  • Steps: Open the registration form and leave a required field empty.
  • Expected: The button should follow the specified disabled-state appearance and behavior.
  • Actual: The button appears identical to an enabled button.
  • Investigation: Check whether the disabled attribute is applied, whether the CSS selector matches, and whether another style overrides the expected appearance.
The actual cause should be confirmed through inspection rather than assumed from the appearance alone.

CSS Interview Questions and Answers

Beginner-level questions

1. What is CSS?
CSS is a stylesheet language used to control the appearance and layout of HTML elements.
2. What are the three types of CSS?
Inline CSS, internal CSS, and external CSS.
3. What is a CSS selector?
A selector identifies which HTML elements a CSS rule should target.
4. What is the difference between an ID and a class?
An ID is intended to identify one unique element within a document. A class can be reused on multiple elements. In CSS, IDs use # and classes use ..
5. What is the CSS box model?
It describes how an element’s content, padding, border, and margin affect its size and spacing.
6. What is the difference between margin and padding?
Margin creates space outside the border, while padding creates space between the content and border.
7. What is the difference between display: none and visibility: hidden?
display: none removes the element from the layout. visibility: hidden hides it but normally preserves its layout space.
8. What is a media query?
A media query applies CSS when specified conditions, such as viewport width, are met.
9. What is the purpose of z-index?
It helps control stacking order within the CSS stacking rules.
10. What is the difference between Flexbox and Grid?
Flexbox primarily handles one-dimensional layouts, while Grid provides a two-dimensional row-and-column layout system.

Intermediate-level questions

11. What is CSS specificity?
Specificity is one factor the browser uses to decide which matching CSS declaration wins. IDs generally have greater specificity than classes, which generally have greater specificity than element selectors.
12. What does box-sizing: border-box do?
It includes padding and border within the specified width and height.
13. What is the difference between relative and absolute positioning?
Relative positioning shifts an element from its normal position while preserving its original layout space. Absolute positioning removes the element from normal flow and positions it relative to its containing block.
14. What is the difference between em and rem?
em is relative to the relevant element’s font size for font sizing, or to the relevant inherited font size for many other properties. rem is relative to the root element’s font size.
15. What is the purpose of overflow: hidden?
It clips content that extends beyond the element’s relevant overflow area.
16. What are pseudo-classes?
Pseudo-classes target elements based on their state or position, such as :hover, :focus, and :first-child.
17. What are pseudo-elements?
Pseudo-elements target a specific part of an element or create generated content, such as ::before and ::after.
18. What is a CSS stacking context?
A stacking context is a group of elements stacked independently within their parent context. It explains why a high z-index element may still appear behind another element.
19. How do you debug a CSS issue?
Inspect the element in Developer Tools, check computed styles, identify the winning CSS declaration, examine parent layout rules, and reproduce the issue at the affected viewport.
20. How do you test responsive design?
Test multiple viewport widths and orientations, inspect breakpoints, verify text and controls, and check supported browsers and real devices as required.

Advanced QA-focused questions

21. How can you identify why a button is not visible?
Inspect the button and its ancestors. Check display, visibility, opacity, dimensions, positioning, overflow, stacking contexts, and responsive rules. Also verify whether the element exists in the DOM.
22. Why might an element be visible in Chrome but not in another browser?
Possible reasons include unsupported CSS features, differences in default styles, font rendering, browser-specific bugs, and different handling of certain layout or form-control behaviors.
23. Why might a CSS selector work locally but fail in automation?
The selector might be incorrect or unstable, the page may not have finished loading, multiple elements may match, or the DOM structure may differ. The automation script may also be looking in the wrong frame or context.
24. How do you test a sticky header?
Scroll the page, verify the header sticks at the expected position, confirm it does not cover important content, and test it at different viewport sizes.
25. How do you investigate an unexpected horizontal scrollbar?
Inspect the document and its overflowing elements. Check fixed widths, long unbroken strings, margins, padding, grid track sizing, flex items, and positioned elements.
High Level QA-focused questions
26. What is the difference between CSS and XPath locators?
CSS selectors locate elements through CSS selector syntax. XPath can locate elements using relationships and conditions in the document tree. Both can be used in UI automation, but the best locator depends on the application and testing requirements.
27. How can you test whether a button’s disabled state is correct?
Verify both the visual state and actual behavior. Check whether the control is disabled as required, whether it can be activated, and whether its appearance matches the specification.
28. Does correct CSS mean the webpage is fully functional?
No. CSS controls presentation. A visually correct page may still have broken links, failed validation, incorrect business logic, or inaccessible interactions.

Practical CSS Testing Exercise

Use the following example to practise inspecting CSS and writing test cases.
<div class="login-card">  <h2>Login</h2>  <label for="email">Email</label> 
<input id="email" type="email" placeholder="Enter email"> <button id="login-btn">Login</button></div>
.login-card {  width: 320px;  padding: 20px;  border: 1px solid #cccccc; 
border-radius: 8px; margin: 20px auto;}.login-card input { display: block; width: 100%; padding: 10px; margin-bottom: 16px; box-sizing: border-box;}#login-btn { width: 100%; padding: 12px; background: #2563eb; color: white; border: none; cursor: pointer;}

Your testing tasks

  1. Verify that the login card is centered.
  2. Check that the email field fits within the card.
  3. Verify that the button has the expected background and text colors.
  4. Test the layout at 320px viewport width.
  5. Check whether the input and button overlap.
  6. Inspect the focus state of the email field.
  7. Test the page at 200% browser zoom.
  8. Inspect the computed width, padding, margin, and border properties.
Important observation: The card has a fixed width of 320px plus 40px of horizontal padding and 2px of border. Under the default content-box sizing, its outer width becomes 362px. On a narrow screen, this can cause horizontal overflow. This is a useful example of a CSS defect a QA tester can identify.
One possible responsive improvement is:
.login-card {  width: 100%;  max-width: 320px;  box-sizing: border-box;  margin: 20px auto;}
This lets the card shrink to fit a narrower containing block while retaining a maximum width of 320px.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top