> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Spacing

export const CssUtilitiesTable = ({utilities}) => {
  const [copiedText, setCopiedText] = useState(null);
  const handleCopy = text => {
    navigator.clipboard.writeText(text).then(() => {
      setCopiedText(text);
      setTimeout(() => {
        setCopiedText(null);
      }, 2000);
    }).catch(err => {
      console.error("Failed to copy text:", err);
    });
  };
  if (!utilities || !Array.isArray(utilities)) {
    return <p className="text-red-500">
        Error: No utilities data provided to CssUtilitiesTable component.
      </p>;
  }
  const CopyableCell = ({text}) => <div className="flex items-center justify-between p-2 rounded-md bg-gray-100 dark:bg-neutral-700 cursor-pointer group w-full" onClick={() => handleCopy(text)} onKeyDown={e => {
    if (e.key === "Enter" || e.key === " ") {
      e.preventDefault();
      handleCopy(text);
    }
  }} role="button" tabIndex={0} title="Click to copy">
      <span className={`text-xs font-mono transition-colors duration-200 ${copiedText === text ? "text-green-800 dark:text-green-500" : "text-gray-700 dark:text-gray-300"}`}>
        {copiedText === text ? "Copied!" : text}
      </span>
      <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="text-gray-400 opacity-0 group-hover:opacity-100 transition-opacity ml-4" viewBox="0 0 24 24">
        <path d="M15 20H5V7c0-.55-.45-1-1-1s-1 .45-1 1v13c0 1.1.9 2 2 2h10c.55 0 1-.45 1-1s-.45-1-1-1m5-4V4c0-1.1-.9-2-2-2H9c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h9c1.1 0 2-.9 2-2m-2 0H9V4h9z"></path>
      </svg>
    </div>;
  return <div className="overflow-x-auto my-6 w-full">
      <table className="min-w-full border-collapse m-0">
        <thead className="bg-gray-50 dark:bg-neutral-900/50">
          <tr className="border-b border-gray-200 dark:border-neutral-800">
            <th className="p-4 text-left text-xs font-semibold text-gray-600 dark:text-gray-400 uppercase tracking-wider">
              SCSS Var
            </th>
            <th className="p-4 text-left text-xs font-semibold text-gray-600 dark:text-gray-400 uppercase tracking-wider">
              CSS Var
            </th>
            <th className="p-4 text-left text-xs font-semibold text-gray-600 dark:text-gray-400 uppercase tracking-wider">
              Value
            </th>
            <th className="w-28 p-4 text-left text-xs font-semibold text-gray-600 dark:text-gray-400 uppercase tracking-wider">
              Value (px)
            </th>
          </tr>
        </thead>
        <tbody className="bg-white dark:bg-neutral-900">
          {utilities.map((item, index) => <tr key={index} className="border-b border-gray-200 dark:border-neutral-800">
              <td className="p-4 align-middle">
                <CopyableCell text={item.scssVar} />
              </td>
              <td className="p-4 align-middle">
                <CopyableCell text={item.cssVar} />
              </td>
              <td className="p-4 align-middle">
                <CopyableCell text={item.value} />
              </td>
              <td className="p-4 align-middle">
                <CopyableCell text={item.valuePx} />
              </td>
            </tr>)}
        </tbody>
      </table>
    </div>;
};

export const LiveCode = ({children, customHeight, clickToLoad, example, fullWidth, fullHeight, hideCodeInLiveCode, screenshot, screenshotOnly, showCode: showCodeProp}) => {
  const SCREENSHOTS_BASE = "https://servicetitan.github.io/anvil2-docs-live-code/screenshots";
  const STACKBLITZ_BASE = "https://stackblitz.com/github/servicetitan/anvil2-docs-live-code/tree/main/examples";
  const [showCodeBlock, setShowCodeBlock] = useState(showCodeProp ?? false);
  const [isLocalOverride, setIsLocalOverride] = useState(false);
  useEffect(() => {
    const examplePath = `/images/live-code-screenshots-tmp/${example}.png`;
    fetch(examplePath, {
      method: "HEAD"
    }).then(r => {
      if (r.ok) setIsLocalOverride(true);
    }).catch(() => {});
  }, [example]);
  const screenshotBase = isLocalOverride ? "/images/live-code-screenshots-tmp" : SCREENSHOTS_BASE;
  if (screenshotOnly) {
    return <Frame className="flex flex-col">
        <div className="flex dark:hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#FFFFFF"
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>
        <div className="hidden dark:flex" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#141414"
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>
      </Frame>;
  }
  if (screenshot) {
    return <Frame className="flex flex-col -mb-2">
        <div className="flex dark:hidden bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>

        <div className="hidden dark:flex bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      background: "#141414",
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>

        <div className="flex justify-end items-center text-xs py-2 px-1 gap-4">
          {!showCodeProp ? <button className="inline-flex justify-end items-center text-gray-700 dark:text-gray-50 hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1 cursor-pointer" onClick={() => setShowCodeBlock(!showCodeBlock)} style={{
      appearance: "none"
    }}>
              <Icon icon="code" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
              <span>{showCodeBlock ? "Hide code" : "Show code"}</span>
            </button> : null}

          <a className="inline-flex justify-end items-center hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1" href={`${STACKBLITZ_BASE}/${example}?file=src/App.tsx`} target="_blank" rel="noreferrer">
            <Icon icon="bolt" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
            <span>StackBlitz demo</span>
          </a>
        </div>

        <div className="grid transition-[grid-template-rows] duration-300 ease-in-out overflow-auto overflow-y-hidden overflow-x-auto" style={showCodeBlock ? {
      gridTemplateRows: "1fr"
    } : {
      gridTemplateRows: "0fr"
    }}>
          <div style={{
      minHeight: 0,
      overflowX: "auto",
      overflowY: "hidden",
      marginBlockStart: "-1.25rem",
      marginBlockEnd: "-1.5rem"
    }}>
            {children}
          </div>
        </div>
      </Frame>;
  } else {
    return <div style={{
      display: "flex",
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px",
      resize: "vertical",
      overflow: "auto"
    }}>
        <iframe title={example} style={{
      flex: 1,
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px"
    }} src={`${STACKBLITZ_BASE}/${example}?embed=1&hideNavigation=1&hideExplorer=1&terminalHeight=0&file=src/App.tsx${clickToLoad ? "&ctl=1" : ""}${hideCodeInLiveCode ? "&view=preview" : ""}`} allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" />
      </div>;
  }
};

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/KE7wVYXA9MgEh_Ye/images/docs/web/foundations/shared/foundations-spacing-overview.png?fit=max&auto=format&n=KE7wVYXA9MgEh_Ye&q=85&s=f69edd36f6049763b929b7ab31319e07"
      alt="Foundations spacing
overview"
      width="144"
      height="144"
      data-path="images/docs/web/foundations/shared/foundations-spacing-overview.png"
    />
  </div>
</Frame>

## Overview

<LiveCode example="spacing-playground" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Flex, Text } from "@servicetitan/anvil2";

  function App() {
    return (
      <Flex gap={4} justifyContent="center" alignItems="flex-end" wrap="wrap">
        {["quarter", "half", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].map(
          (sizeValue, i) => (
            <Flex key={i} direction="column" alignItems="center">
              <div
                style={{
                  height: `var(--size-${sizeValue})`,
                  width: `var(--size-${sizeValue})`,
                  background: `hsl(${25 * i}, 50%, 80%)`,
                }}
              />
              <Text size="small" color="subdued">
                {sizeValue}
              </Text>
            </Flex>
          ),
        )}
      </Flex>
    );
  }

  export default App;
  ```
</LiveCode>

Anvil2 uses partial increments of a base-`0.5rem` spacing scale. Quarter and half values of `0.0625rem` and `0.125rem` are also included.

## CSS Utilities

Anvil provides size utility variables for common spacing needs.

export const spacingUtilities = [{
  scssVar: "$size-0",
  cssVar: "--size-0",
  value: "0rem",
  valuePx: "0px"
}, {
  scssVar: "$size-quarter",
  cssVar: "--size-quarter",
  value: "0.0625rem",
  valuePx: "1px"
}, {
  scssVar: "$size-half",
  cssVar: "--size-half",
  value: "0.125rem",
  valuePx: "2px"
}, {
  scssVar: "$size-1",
  cssVar: "--size-1",
  value: "0.25rem",
  valuePx: "4px"
}, {
  scssVar: "$size-2",
  cssVar: "--size-2",
  value: "0.5rem",
  valuePx: "8px"
}, {
  scssVar: "$size-3",
  cssVar: "--size-3",
  value: "0.75rem",
  valuePx: "12px"
}, {
  scssVar: "$size-4",
  cssVar: "--size-4",
  value: "1rem",
  valuePx: "16px"
}, {
  scssVar: "$size-5",
  cssVar: "--size-5",
  value: "1.25rem",
  valuePx: "20px"
}, {
  scssVar: "$size-6",
  cssVar: "--size-6",
  value: "1.5rem",
  valuePx: "24px"
}, {
  scssVar: "$size-7",
  cssVar: "--size-7",
  value: "1.75rem",
  valuePx: "28px"
}, {
  scssVar: "$size-8",
  cssVar: "--size-8",
  value: "2rem",
  valuePx: "32px"
}, {
  scssVar: "$size-9",
  cssVar: "--size-9",
  value: "2.25rem",
  valuePx: "36px"
}, {
  scssVar: "$size-10",
  cssVar: "--size-10",
  value: "2.5rem",
  valuePx: "40px"
}, {
  scssVar: "$size-11",
  cssVar: "--size-11",
  value: "2.75rem",
  valuePx: "44px"
}, {
  scssVar: "$size-12",
  cssVar: "--size-12",
  value: "3rem",
  valuePx: "48px"
}, {
  scssVar: "$size-13",
  cssVar: "--size-13",
  value: "3.25rem",
  valuePx: "52px"
}, {
  scssVar: "$size-14",
  cssVar: "--size-14",
  value: "3.5rem",
  valuePx: "56px"
}];

<CssUtilitiesTable utilities={spacingUtilities} />
