What Is CSS? Layout and Responsive Design Explained

CSS is the language used to tell a web browser how a page should look and how its contents should fit together. It can make a heading larger, put space between two buttons, or arrange products side by side. It can also change that arrangement when someone opens the same page on a smaller screen.

Imagine a restaurant supplier hands you a printed order sheet. It lists washed carrots in 5 kg boxes and loose carrots in 1 kg bags. Both products have a space where you can write a quantity. If each space sits next to the right product and unit, ordering 10 kg is easy. If the sheet puts both spaces at the bottom under a single heading called “Quantity”, you have to guess where to write your number.

The words on the sheet can be accurate in both versions. Their arrangement changes how easily you can use them. On the web, that is the job of CSS layout. A responsive interface takes the idea one step further. It preserves those relationships as the space available to display them changes.

What does CSS do on a web page?

CSS stands for Cascading Style Sheets. A style sheet is a collection of presentation rules. A website can keep those rules in a file and apply them across many pages. For a supplier with a hundred products, that means one rule can give every product card the same spacing.

To understand where CSS fits, consider one entry in the supplier’s catalogue. HTML identifies “Washed carrots” as a heading, “Number of boxes (5 kg each)” as a label, and the box where you type as a number field. Even before the supplier adds its own CSS, a browser gives these elements a basic appearance. You can already read the heading and type a number.

CSS lets the supplier decide how that entry should appear in its own catalogue. It can draw a border around the product, leave a small space between the label and its input, and leave a larger space before the next product. You can see at a glance which field belongs to the carrots. The earlier article on what HTML defines on a web page explains how the browser knows which text labels the field in the first place.

How to read your first CSS rule

Suppose the words “Washed carrots” sit so close to the card’s border that the top of the catalogue feels cramped. Here is a rule a developer could write to give the contents some room.

.product-card {
  padding: 16px;
}

Read it as a sentence: “For every element marked as a product card, leave 16 pixels of space on the inside.” Each part of the rule has a job.

  • .product-card chooses what to change. The dot tells the browser to look for an HTML class named product-card. A class is a name the developer can give to several elements that should share a style.
  • padding chooses which detail to change. Padding is the space between the content and the inside edge of its box.
  • 16px supplies the value. Here it means 16 CSS pixels on each side. If you change it to 24px, the contents sit farther from the edge.

Why “cascading”? More than one rule can apply to the same element. A site might give all product cards 16 pixels of padding, then use a more specific rule for cards in a compact order summary. The cascade is the set of rules the browser uses to decide which value wins. That is how a site can share a common design and still make a particular screen look different.

What is the CSS box model?

Imagine drawing a rectangle around one product on the printed order sheet. The product name and quantity field are the content. The blank paper between the words and your line is the padding. The line itself is the border. Space outside that line can be created with a margin. Together, these parts make up the CSS box model.

The distinction matters when you are trying to fix what you see. If “Washed carrots” touches its border, increase the card’s padding. If the carrot card nearly touches the potato card below it, increase the gap between cards. Adding more space inside both cards would make them taller while leaving their borders just as close together.

Some layout work happens automatically. A long product name usually wraps when it runs out of room. In the browser’s normal flow, that extra line pushes the content beneath it down. If a developer gives every card a fixed height based on the short name “Carrots”, a longer name such as “Washed carrots for roasting” can leave too little room for the field. Letting the card grow preserves the whole entry.

What makes a layout responsive?

Return to the restaurant buyer. At a desk, you might compare two packs side by side. In the kitchen, you might hold your phone in one hand while checking how many carrots are left. The same two-column catalogue now gives each product only half of a narrow screen.

A responsive layout can put one product below the other on the phone. The text stays readable, and each field stays with its own pack size. You scroll a little farther, but you can still see that entering 2 boxes of 5 kg requests the 10 kg the kitchen needs. Entering 2 bags of 1 kg requests only 2 kg.

This is why shrinking a desktop page can produce a poor mobile experience. It preserves the picture of the catalogue while making the buyer work harder to read it. Stacking the products changes the picture and preserves the task.

When should you use CSS Grid or Flexbox?

CSS Grid is useful when several items should line up in shared rows and columns. Picture shelves in a shop. The first product on each shelf starts in the same place, so your eye can follow a column down the display. In the catalogue, Grid can give the box of carrots and the bag of carrots equally wide cards. The next pair of products can line up beneath them.

Flexbox is useful when you have a sequence of items to arrange in a row or column. Inside one product card, for example, you might want the quantity field and a “Check availability” button next to each other. If the button no longer fits, Flexbox can move it onto the next line.

The important decision is what should move together. Keep “Number of boxes (5 kg each)” and its input in one group. Let that group and the button move relative to each other. The button can drop to a new line without separating the number 2 from the words that explain it.

A small responsive catalogue you can read line by line

Here is the HTML for the two pack sizes. Even if you have never written code, look for the repeated pattern. Each product has a heading, a label with its ordering unit, and a field. The first field contains 2, so the example represents two 5 kg boxes.

<div class="catalogue">
  <div class="product-card">
    <h3>Washed carrots</h3>
    <label class="quantity">
      Number of boxes (5 kg each)
      <input type="number" min="0" value="2">
    </label>
  </div>

<div class="product-card"> <h3>Loose carrots</h3> <label class="quantity"> Number of bags (1 kg each) <input type="number" min="0" value="0"> </label> </div> </div>

Now add the CSS. Start by reading the first rule and the last rule. Together they tell the main story: show one column by default, then make room for a second column when the browser is wide enough.

.catalogue {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.product-card { padding: 1rem; border: 1px solid #888; }

.product-card h3 { margin: 0 0 0.75rem; }

.quantity { display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; }

.quantity input { box-sizing: border-box; width: 6rem; max-width: 100%; font: inherit; }

@media (min-width: 48rem) { .catalogue { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

What should you see? In a narrow browser window, the box of carrots appears above the bag. Inside each card, Flexbox puts the quantity input immediately below its label. The small gap inside the label group is deliberate. It is smaller than the gap between products, so each number stays visually connected to its unit.

Widen the window and the two products appear side by side. The final rule, called a media query, tells the browser when to make that change. repeat(2, minmax(0, 1fr)) creates two columns that share the available width equally and can shrink. A rem is a unit based on the page’s root font size. Using it lets the example express spacing and widths in terms related to the size of the text.

The fields in this example let you edit quantities. In a working ordering system, submitting those values and confirming what the supplier has in stock would require application logic and product data. The CSS handles how clearly the buyer can see and use the fields.

How do you choose the right breakpoint?

A breakpoint is where a layout rule changes. In the example, that point is 48rem. To find a suitable breakpoint for a real catalogue, try its most demanding content. Replace “5 kg each” with “4 bags of 1.25 kg per box”. Then slowly narrow the browser. Can you still tell that entering 2 means two whole boxes?

Let the answer guide the design. A label wrapping onto a second line can be perfectly readable. A label cut off after “1.25 kg” loses the words that explain how the product is sold. If keeping two columns requires hiding those words, switch to one column sooner or give the card more room to grow.

Sometimes the card’s own space matters more than the browser width. A laptop can display a wide catalogue and a narrow “Order again” panel at the same time. A container query lets the content respond to the width of its surrounding panel. The panel can keep one column while the main catalogue shows two. The MDN guide to CSS container queries shows how to set that up.

How can you tell whether the layout works?

Give someone the catalogue and ask them to request 10 kg of carrots in boxes. Let them choose the field and enter the number themselves. Then ask, “What do you expect the supplier to deliver?” Their answer tells you whether the interface communicated the ordering unit.

  • On a phone, tap the quantity field. When the on-screen keyboard appears, check whether the pack size is still easy to find.
  • With larger text, read the longest product label. The card should grow enough to show the complete unit and leave the input reachable.
  • With a keyboard, press Tab through the catalogue. Focus should follow a sequence that makes sense from the visible order of the products.
  • In the order summary, check what the number means after leaving the catalogue. “2 boxes · 10 kg total” gives the buyer a chance to catch a mistake before confirming.

Why this matters in a wholesale ordering app

As Technical Lead at Apps Panel / Nomeo, I worked on an ordering application for a food wholesaler. Professional customers could browse the catalogue, manage their accounts, place orders and track them. The app also synchronised with the wholesaler’s existing information system.

The carrot catalogue is an illustrative web example of a question that comes up in this kind of product. Where does “5 kg per box” come from, and where does the buyer need to see it? The supplier’s system holds the pack information. The interface needs to keep it visible when someone compares products, enters a quantity and reviews the order. If the unit disappears during any of those steps, a number can change meaning in the buyer’s eyes even though the underlying data stays the same.

If you are planning an ordering MVP, a useful starting point is one real product entry and the confirmation your customer should receive. I can help map the screens between them and identify what data each one needs. Explore my mobile development and backend expertise.