Code Snippets Library

Responsive Meta Tag

The standard meta viewport tag for responsive web design.

<meta name="viewport" content="width=device-width, initial-scale=1.0">
htmlresponsive

Center Element with Flexbox

Easily center an element both vertically and horizontally.

.container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
cssflexbox

Fetch API GET Request

Make a simple GET request using async/await.

async function getData() {
    try {
        const response = await fetch('https://api.example.com/data');
        const data = await response.json();
        console.log(data);
    } catch (error) {
        console.error('Error:', error);
    }
}
javascriptapi

useState Counter

A simple counter component using hooks.

import { useState } from 'react';

function Counter() {
    const [count, setCount] = useState(0);
    return (
        <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
    );
}
reacthooks