.. _responsive-design:
Responsive Design Guidelines
=============================
Comprehensive guidelines for building responsive, mobile-first applications with Buildly.
.. contents:: Table of Contents
:local:
:depth: 2
Overview
--------
Responsive design ensures your application works seamlessly across all devices and screen sizes. This guide covers Buildly's responsive design patterns, breakpoints, and best practices.
Design Philosophy
-----------------
**Mobile-First Approach**
Start with mobile design and progressively enhance for larger screens:
- Design for smallest screens first
- Add complexity as screen size increases
- Ensure core functionality works on all devices
- Progressive enhancement over graceful degradation
**Fluid Layouts**
- Use percentage-based widths
- Flexible grids and containers
- Scalable images and media
- Relative units (rem, em, %, vw, vh)
Breakpoint System
-----------------
Standard Breakpoints
~~~~~~~~~~~~~~~~~~~~
Buildly uses a consistent breakpoint system across frameworks:
.. code-block:: javascript
const breakpoints = {
xs: '0px', // Extra small: phones (portrait)
sm: '600px', // Small: phones (landscape)
md: '960px', // Medium: tablets
lg: '1280px', // Large: desktops
xl: '1920px', // Extra large: large desktops
};
**Usage in CSS:**
.. code-block:: css
/* Mobile first - base styles */
.container {
padding: 16px;
font-size: 14px;
}
/* Tablet and up */
@media (min-width: 960px) {
.container {
padding: 24px;
font-size: 16px;
max-width: 1200px;
margin: 0 auto;
}
}
/* Desktop and up */
@media (min-width: 1280px) {
.container {
padding: 32px;
}
}
**Material-UI Breakpoints:**
.. code-block:: jsx
import { useTheme, useMediaQuery } from '@mui/material';
function ResponsiveComponent() {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const isTablet = useMediaQuery(theme.breakpoints.between('sm', 'md'));
const isDesktop = useMediaQuery(theme.breakpoints.up('lg'));
return (
{isMobile && }
{isTablet && }
{isDesktop && }
);
}
Grid Systems
------------
Flexible Grid Layout
~~~~~~~~~~~~~~~~~~~~
**CSS Grid:**
.. code-block:: css
.grid-container {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 24px;
padding: 24px;
}
.grid-item {
grid-column: span 12; /* Full width on mobile */
}
@media (min-width: 960px) {
.grid-item {
grid-column: span 6; /* Half width on tablet */
}
}
@media (min-width: 1280px) {
.grid-item {
grid-column: span 4; /* Third width on desktop */
}
}
**Material-UI Grid:**
.. code-block:: jsx
import { Grid, Container } from '@mui/material';
function ResponsiveGrid() {
return (
Content 1
Content 2
Content 3
Content 4
);
}
Flexbox Patterns
~~~~~~~~~~~~~~~~
.. code-block:: css
/* Responsive flex layout */
.flex-container {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
.flex-item {
flex: 1 1 100%; /* Stack on mobile */
min-width: 280px;
}
@media (min-width: 960px) {
.flex-item {
flex: 1 1 calc(50% - 16px); /* Two columns on tablet */
}
}
@media (min-width: 1280px) {
.flex-item {
flex: 1 1 calc(33.333% - 16px); /* Three columns on desktop */
}
}
Typography
----------
Responsive Font Sizing
~~~~~~~~~~~~~~~~~~~~~~~
**Fluid Typography:**
.. code-block:: css
/* Using clamp() for fluid scaling */
h1 {
font-size: clamp(1.5rem, 4vw, 3rem);
line-height: 1.2;
}
h2 {
font-size: clamp(1.25rem, 3vw, 2.5rem);
}
body {
font-size: clamp(0.875rem, 1.5vw, 1rem);
line-height: 1.6;
}
**Breakpoint-Based Scaling:**
.. code-block:: jsx
const theme = createTheme({
typography: {
h1: {
fontSize: '2rem',
'@media (min-width:960px)': {
fontSize: '2.5rem',
},
'@media (min-width:1280px)': {
fontSize: '3rem',
},
},
},
});
Images and Media
----------------
Responsive Images
~~~~~~~~~~~~~~~~~
**HTML Picture Element:**
.. code-block:: html
**CSS Background Images:**
.. code-block:: css
.hero {
background-image: url('hero-small.jpg');
background-size: cover;
background-position: center;
}
@media (min-width: 960px) {
.hero {
background-image: url('hero-medium.jpg');
}
}
@media (min-width: 1280px) {
.hero {
background-image: url('hero-large.jpg');
}
}
**React Responsive Images:**
.. code-block:: jsx
function ResponsiveImage({ alt, sizes }) {
return (
);
}
Navigation Patterns
-------------------
Mobile Navigation
~~~~~~~~~~~~~~~~~
**Hamburger Menu:**
.. code-block:: jsx
import { useState } from 'react';
import {
AppBar,
Toolbar,
IconButton,
Drawer,
List,
ListItem,
useMediaQuery,
useTheme
} from '@mui/material';
import MenuIcon from '@mui/icons-material/Menu';
function ResponsiveNav() {
const [drawerOpen, setDrawerOpen] = useState(false);
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
return (
<>
{isMobile ? (
<>
setDrawerOpen(true)}
>
setDrawerOpen(false)}
>
setDrawerOpen(false)} />
>
) : (
)}
>
);
}
Tables and Data Display
-----------------------
Responsive Tables
~~~~~~~~~~~~~~~~~
**Scrollable Tables:**
.. code-block:: jsx
import { TableContainer, Paper } from '@mui/material';
function ResponsiveTable() {
return (
);
}
**Card-Based Mobile Layout:**
.. code-block:: jsx
function ResponsiveDataDisplay({ data }) {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
if (isMobile) {
return (
{data.map(item => (
{item.title}
{item.description}
))}
);
}
return ;
}
Forms
-----
Responsive Form Layouts
~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: jsx
function ResponsiveForm() {
return (
);
}
Touch Optimization
------------------
Touch Targets
~~~~~~~~~~~~~
Ensure interactive elements are large enough for touch:
.. code-block:: css
/* Minimum touch target size */
.button,
.link,
.interactive {
min-height: 44px;
min-width: 44px;
padding: 12px 16px;
}
/* Spacing between touch targets */
.button-group button {
margin: 8px;
}
**Material-UI Touch Ripple:**
.. code-block:: jsx
Performance Optimization
------------------------
Viewport Configuration
~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: html
Lazy Loading
~~~~~~~~~~~~
.. code-block:: jsx
import { lazy, Suspense } from 'react';
const HeavyComponent = lazy(() => import('./HeavyComponent'));
function App() {
return (
}>
);
}
CSS Optimization
~~~~~~~~~~~~~~~~
.. code-block:: css
/* Use CSS containment for performance */
.card {
contain: layout style paint;
}
/* Hardware acceleration for animations */
.animated {
will-change: transform;
transform: translateZ(0);
}
Testing Responsive Designs
---------------------------
Browser DevTools
~~~~~~~~~~~~~~~~
1. Open Chrome DevTools (F12)
2. Click device toolbar icon (Ctrl+Shift+M)
3. Test different device presets
4. Test custom dimensions
5. Test network throttling
Automated Testing
~~~~~~~~~~~~~~~~~
.. code-block:: javascript
// Using Cypress for responsive testing
describe('Responsive Layout', () => {
const sizes = ['iphone-6', 'ipad-2', [1280, 720]];
sizes.forEach(size => {
it(`displays correctly on ${size}`, () => {
if (Cypress._.isArray(size)) {
cy.viewport(size[0], size[1]);
} else {
cy.viewport(size);
}
cy.visit('/');
cy.get('.main-nav').should('be.visible');
cy.screenshot(`${size}-viewport`);
});
});
});
Best Practices
--------------
✅ **DO:**
- Start with mobile design
- Use relative units (rem, em, %)
- Test on real devices
- Optimize images for different sizes
- Use CSS containment
- Implement touch-friendly interactions
- Test with slow network speeds
❌ **DON'T:**
- Use fixed pixel widths
- Ignore small screen sizes
- Load desktop-sized images on mobile
- Make touch targets too small
- Use hover-only interactions
- Forget about landscape orientation
- Assume screen dimensions
Common Patterns
---------------
Dashboard Layout
~~~~~~~~~~~~~~~~
.. code-block:: jsx
function ResponsiveDashboard() {
return (
{/* More grid items */}
);
}
Content with Sidebar
~~~~~~~~~~~~~~~~~~~~
.. code-block:: jsx
function ContentLayout() {
return (
);
}
Resources
---------
**Tools:**
- Chrome DevTools Device Mode
- Firefox Responsive Design Mode
- BrowserStack for real device testing
- Lighthouse for performance auditing
**Further Reading:**
- :doc:`/frontend/index` - Frontend development guide
- MDN Responsive Design Guide
- Google Web Fundamentals
**Video Resources:**
- `Buildly YouTube Channel `_ - Responsive design tutorials and best practices
- `OpenBuild YouTube Channel `_ - Mobile-first design patterns
.. note::
Continuously test your responsive designs on real devices and various browsers to ensure the best user experience.