Basic Pseudo-Classes
1. Interactive Navigation Menu
Project: Create a navigation menu where links change appearance on hover, active, and visited states. Instructions:
- Design a horizontal navigation menu with 5 links
- Style
:hoverto change background color and text color - Use
:activeto create a "pressed" effect - Style
:visitedlinks differently from unvisited links - Add a smooth transition between states
2. Form Input Focus Effects
Project: Build a contact form with dynamic focus states. Instructions:
- Create a simple contact form with name, email, and message fields
- Use
:focusto highlight the active input field - Add a border animation when an input receives focus
- Change the label color when its associated input is focused
- Reset styles when focus is lost
3. Link States Showcase
Project: Create a demonstration page showing all link states. Instructions:
- Create sections for each link state (
:link,:visited,:hover,:active) - Style each state with distinct visual cues
- Add explanatory text for each state
- Include examples showing the states in context
4. First-Child Header Effects
Project: Build a blog layout with special styling for the first header. Instructions:
- Create a blog post template with multiple headers
- Use
:first-childto style the first heading differently - Apply special typography, size, and decoration to the first heading
- Create a visual hierarchy that emphasizes the first heading
5. Last-Child Footer Elements
Project: Design a footer where the last element has special styling. Instructions:
- Create a multi-column footer with various elements
- Use
:last-childto style the last element differently - Add a different background, border, or spacing to the last item
- Ensure responsive behavior maintains the special styling
Structural Pseudo-Classes
6. Zebra Striping Table Rows
Project: Create a data table with alternating row colors. Instructions:
- Build a table with at least 10 rows of data
- Use
:nth-child(even)and:nth-child(odd)to create zebra striping - Add hover effects for better row identification
- Style header row differently using
:first-child
7. Prime-Numbered List Items
Project: Design a numbered list where prime-numbered items have special styling. Instructions:
- Create a list with at least 20 items
- Use
:nth-child(2),:nth-child(3),:nth-child(5), etc. to style prime-numbered items - Add a distinct visual identifier for prime numbers
- Include an explanation of the pattern
8. Calendar Layout with Current Day Highlight
Project: Build a monthly calendar with special styling for today's date. Instructions:
- Create a grid-based calendar layout
- Use
:nth-child()to style weekends differently - Add a unique style for the current date
- Include hover effects for all calendar days
9. Photo Gallery with Featured Images
Project: Create an image gallery where every third image is featured. Instructions:
- Build a responsive grid of 12+ images
- Use
:nth-child(3n)to make every third image larger - Add different hover effects for regular vs. featured images
- Ensure the layout is responsive across device sizes
10. Article Cards with Even/Odd Styling
Project: Design a list of article cards with alternating layouts. Instructions:
- Create 6+ article cards with image, title, and excerpt
- Use
:nth-child(odd)to align images on the left - Use
:nth-child(even)to align images on the right - Add different color accents for odd vs. even cards
11. Team Member Grid with Row-Based Styling
Project: Build a team directory with different styling per row. Instructions:
- Create a grid of team members with photos and info
- Use
:nth-child(3n+1),:nth-child(3n+2), and:nth-child(3n+3)for different row styles - Apply different background colors or borders per row
- Maintain consistent styling when viewed on different devices
12. Only-Child Special Case
Project: Create a component that changes style when it contains only one child. Instructions:
- Build a container that can hold variable numbers of items
- Use
:only-childto apply special styling when only one item exists - Create a demo showing the difference between multiple children vs. only child
- Include interactive controls to add/remove items
13. First-of-Type Section Highlights
Project: Design a page where the first occurrence of each content type has special styling. Instructions:
- Create a page with multiple paragraphs, images, lists, and quotes
- Use
:first-of-typeto style the first occurrence of each element type - Apply distinct visual treatments for each first element
- Add explanatory notes about how the selector works
14. Last-of-Type Section Footers
Project: Build a layout where the last instance of each section type has a special footer. Instructions:
- Create multiple sections with different content types
- Use
:last-of-typeto add special footers to the last instance of each type - Style the footers with distinct visual treatments
- Explain the difference between
:last-childand:last-of-type
Form Pseudo-Classes
15. Form Validation Visual Feedback
Project: Create a form with visual cues for valid and invalid inputs. Instructions:
- Build a registration form with various input types
- Use
:validand:invalidto provide real-time visual feedback - Style valid inputs with green accents and checkmarks
- Style invalid inputs with red accents and error icons
- Add helpful tooltips explaining validation requirements
16. Required Field Indicators
Project: Design a form that visually indicates which fields are required. Instructions:
- Create a form with both optional and required fields
- Use
:requiredto automatically style required fields - Add visual indicators (asterisks, text, icons) to required fields
- Use
:optionalto style optional fields differently
17. Checkbox and Radio Button Customization
Project: Build custom-styled checkboxes and radio buttons. Instructions:
- Create a form with multiple checkboxes and radio groups
- Use
:checkedto create custom-styled selected states - Design visually appealing replacements for default browser styles
- Ensure accessibility is maintained with proper focus states
18. Disabled Form Elements
Project: Create a form demonstrating proper styling for disabled elements. Instructions:
- Build a form with some disabled fields
- Use
:disabledto style disabled elements appropriately - Create visual cues that clearly indicate which elements can't be used
- Include a toggle to enable/disable fields for demonstration
19. Read-Only vs. Editable Fields
Project: Design a form that distinguishes between editable and read-only fields. Instructions:
- Create a form with both editable and read-only fields
- Use
:read-onlyand:read-writeto style fields appropriately - Apply distinct visual treatments to indicate which fields can be edited
- Include explanations of when to use read-only fields
20. In-Range and Out-of-Range Feedback
Project: Build a form with number inputs that show when values are in/out of range. Instructions:
- Create number inputs with min/max attributes
- Use
:in-rangeand:out-of-rangeto provide visual feedback - Style out-of-range values with warning colors and icons
- Add explanatory text describing the acceptable ranges
21. Form Placeholder Styling
Project: Design form fields with custom-styled placeholders. Instructions:
- Create a form with various input types using placeholders
- Use
::placeholderto style placeholder text - Apply custom colors, fonts, and opacity to placeholders
- Create a cohesive design that enhances usability
22. Focus-Within Form Groups
Project: Build form groups that highlight when any child element is focused. Instructions:
- Create logical form groups with labels and inputs
- Use
:focus-withinto highlight the entire group when any child has focus - Style the parent container with a subtle background or border change
- Explain the difference between
:focusand:focus-within
Advanced Selectors
23. Target Section Navigation
Project: Create a single-page site with sections that highlight when targeted with URL fragments. Instructions:
- Build a page with multiple sections and an anchor navigation
- Use
:targetto highlight the active section - Add animation or transition effects when a section becomes targeted
- Style the navigation to show the current target
24. Empty Content Placeholders
Project: Design a content management interface that shows placeholders for empty elements. Instructions:
- Create a layout with various content containers
- Use
:emptyto detect and style containers with no content - Design helpful placeholder messages or icons for empty states
- Add a demo that allows adding/removing content to see the effect
25. Not-Selector Menu Highlighting
Project: Build a navigation menu that highlights all items except the current page. Instructions:
- Create a multi-page navigation menu
- Use
:not(.current)to style non-active items differently - Apply hover effects only to items that aren't the current page
- Include a demonstration of how this enhances usability
26. Language-Specific Styling
Project: Design a multilingual page with styling based on language attributes. Instructions:
- Create a page with content in multiple languages
- Use
:lang(xx)to apply language-specific styling - Add appropriate typography adjustments for different languages
- Include culturally appropriate color schemes or icons
27. Has-Selector Content Relationships
Project: Build containers that change style based on the types of content they contain. Instructions:
- Create various content containers with different child elements
- Use
:has(img),:has(table), etc. to detect and style containers accordingly - Apply layout adjustments based on content type
- Explain how this helps create adaptive layouts
28. Attribute-Based Link Styling
Project: Design a page where links are styled based on their attributes. Instructions:
- Create a page with various types of links (internal, external, downloads)
- Use
[href^="http"],[href$=".pdf"], etc. to detect link types - Apply distinct styles and icons for each link type
- Include a legend explaining what each style indicates
Interactive Components
29. Accordion Without JavaScript
Project: Build an accordion component using only CSS. Instructions:
- Create an accordion with multiple sections
- Use
:targetor:checkedwith hidden inputs to toggle sections - Style the open and closed states differently
- Add smooth transitions between states
30. CSS-Only Tabs Interface
Project: Design a tabbed interface without using JavaScript. Instructions:
- Create a component with multiple tabbed sections
- Use
:checkedwith radio inputs to control tab visibility - Style active tabs distinctly from inactive tabs
- Ensure accessible keyboard navigation
31. Hover-Triggered Dropdown Menu
Project: Build a navigation menu with dropdowns that appear on hover. Instructions:
- Create a main navigation with nested dropdown menus
- Use
:hoverto reveal dropdown content - Add transitions for smooth appearance/disappearance
- Ensure the dropdown remains visible when hovering over its content
32. Focus-Triggered Tooltips
Project: Design form fields with tooltips that appear on focus. Instructions:
- Create form fields with associated help information
- Use
:focusto display tooltips when fields receive focus - Position tooltips appropriately relative to their fields
- Style tooltips to be clearly visible without overwhelming the interface
33. Active State Animations
Project: Build buttons with special animations when clicked. Instructions:
- Create a set of action buttons with different purposes
- Use
:activeto trigger animations when buttons are pressed - Design animations that provide visual feedback about the click
- Ensure animations complete quickly enough for good UX
34. Checked State Toggle Switches
Project: Design custom toggle switches using checkboxes. Instructions:
- Create toggle switches for various settings
- Use
:checkedto style the on/off states - Design visually appealing switch controls
- Add appropriate labels and color coding for states
35. Required + Invalid Error Messages
Project: Build form fields that display error messages for invalid required fields. Instructions:
- Create form fields with validation requirements
- Use
:required:invalidto target invalid required fields - Display appropriate error messages for different validation issues
- Style error messages to be noticeable but not disruptive
36. Focus-Within Card Highlighting
Project: Design content cards that highlight when any element inside receives focus. Instructions:
- Create a grid of interactive content cards
- Use
:focus-withinto highlight entire cards when they contain focused elements - Add visual enhancements that draw attention to the active card
- Ensure the highlighting doesn't interfere with readability
Creative Applications
37. Typing Indicator Animation
Project: Create a text input that shows an animation while the user is typing. Instructions:
- Build a comment or message input field
- Use
:focuscombined with animation to show a "typing" indicator - Design an unobtrusive but noticeable animation
- Reset the animation when focus is lost
38. Parent Hover Child Animations
Project: Design a gallery where hovering over images triggers animations in captions. Instructions:
- Create an image gallery with captions
- Use parent
:hoverto trigger animations in child elements - Design varied animations for different aspects of the caption
- Ensure animations enhance rather than distract from content
39. Hover-to-Reveal Image Captions
Project: Build an image gallery with captions that appear on hover. Instructions:
- Create a grid of images with hidden captions
- Use
:hoverto reveal caption information - Design smooth transitions for caption appearance
- Ensure captions are readable against any background
40. Scrollbar Customization
Project: Design a page with custom-styled scrollbars. Instructions:
- Create a page with enough content to require scrolling
- Use
::-webkit-scrollbarand related pseudo-elements to style scrollbars - Design scrollbars that match your site's aesthetic
- Provide fallbacks for browsers that don't support scrollbar styling
41. First-Letter Drop Caps
Project: Build an article layout with decorative first letters. Instructions:
- Create an article with multiple paragraphs
- Use
::first-letterto style the first letter of paragraphs - Design drop caps that enhance the typography without hampering readability
- Vary the styling for different paragraph types
42. Selection Styling
Project: Design a page with custom-styled text selection. Instructions:
- Create a text-heavy page with various content types
- Use
::selectionto customize how selected text appears - Choose colors that maintain good contrast and readability
- Consider different selection styles for different content areas
43. Before and After Decorative Elements
Project: Build headings with decorative elements created using pseudo-elements. Instructions:
- Create various heading styles with decorative elements
- Use
::beforeand::afterto add icons, lines, or shapes - Position the decorative elements appropriately
- Ensure decorations enhance rather than compete with content
44. Tooltip Position Based on Screen Edge
Project: Design tooltips that reposition based on their proximity to screen edges. Instructions:
- Create interactive elements with tooltips
- Use JavaScript to detect proximity to edges
- Apply different classes that trigger different
:before/:afterpositioning - Ensure tooltips remain fully visible regardless of position
45. Progress Tracker with Current Step Highlighting
Project: Build a multi-step process indicator. Instructions:
- Create a horizontal or vertical step indicator
- Use
:nth-childcombined with acurrentclass to highlight the active step - Style completed steps differently from upcoming steps
- Add appropriate connecting lines or arrows between steps
Responsive Applications
46. Media Query + Pseudo-Class Combinations
Project: Design elements that use different pseudo-class behaviors at different screen sizes. Instructions:
- Create interactive elements that behave differently on mobile vs. desktop
- Use media queries combined with pseudo-classes
- Implement hover effects on desktop that transform to active/focus effects on mobile
- Explain the reasoning behind the different interactions
47. Nth-Child Responsive Grid
Project: Build a grid layout where every nth item changes behavior responsively. Instructions:
- Create a grid of content items
- Use
:nth-child()to target specific items - Apply different styles or layout adjustments at different breakpoints
- Ensure the design maintains visual harmony across screen sizes
48. Responsive Navigation with Active States
Project: Design a navigation that transforms from horizontal to hamburger menu. Instructions:
- Create a navigation that's horizontal on desktop and toggleable on mobile
- Use
:checkedwith a hidden checkbox to control mobile menu visibility - Style active states appropriately for both layouts
- Ensure smooth transitions between states and layouts
49. Form Field Focus States Across Devices
Project: Build a form with focus states optimized for different input methods. Instructions:
- Create a form that works well on touchscreens and with keyboards
- Use
:focus-visiblefor keyboard users and appropriate touch states - Design states that work well with both precision and touch inputs
- Test and optimize for various devices and input methods
50. Accessibility-Enhanced Interactive Elements
Project: Design interactive elements with states for all types of interactions. Instructions:
- Create buttons, links, and form controls with comprehensive state styling
- Use
:hover,:focus,:active, and:focus-visibleappropriately - Ensure high contrast and clear visual indicators for all states
- Test with keyboard, mouse, touch, and screen readers to verify accessibility
Each of these projects explores different aspects of CSS pseudo-classes, providing a comprehensive learning experience. They range from basic to advanced and cover various real-world applications. As you work through them, you'll develop a deep understanding of how pseudo-classes can enhance your web design capabilities.