Thuta Learning
BasicWeb Developmentintermediate

CSS, Images, and Fonts

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Know when to use global CSS versus scoped CSS
  • Optimize images with the Image component
  • Manage font loading so it doesn't cause layout shift

Knowing how to write CSS isn't enough to make a UI look good. In production, you need to avoid things like a page slowing down because of an oversized image, or text jumping around when a font loads in. Next.js helps with these at the framework level.

The key idea

Import globals.css from the root layout, and keep site-wide styles like resets, color tokens, and typography there. Writing component-specific styles as *.module.css avoids class name collisions. next/image knows the image size ahead of time, so it prevents layout shift and can serve the right size and format. next/font optimizes font files at build time, cutting down on external requests.

Let's try it together

tsx
import Image from "next/image";
import styles from "./note-card.module.css";

export function NoteCard() {
  return (
    <article className={styles.card}>
      <Image
        src="/notebook.jpg"
        width={640}
        height={360}
        alt="စားပွဲပေါ်ရှိ မှတ်စုစာအုပ်"
        className={styles.cover}
      />
      <h2>ဒီနေ့လေ့လာခဲ့တာ</h2>
    </article>
  );
}

How the code works

Image includes width, height, and a meaningful alt. The CSS Module class is referenced as styles.cover, so it won't clash with a cover class in another component.

You should see
A note card appears with a stable size and an optimized image.

5-Minute Try-It

Add an image to the public folder and write a responsive NoteCard. Write the alt text so it makes sense to someone who can't see the image.

Next.js — Image OptimizationNext.js

Easy traps

  • Not setting width/height or a fill container size on the Image component
  • Dumping every component's styles into globals.css

Exercise

Add an image to the public folder and write a responsive NoteCard. Write the alt text so it makes sense to someone who can't see the image.

You'll know it worked when: A note card appears with a stable size and an optimized image.

CSS, Images, and Fonts | Thuta Learning