Amplify UI

Heading

Heading renders semantic section heading text representing six levels.

Demo

Usage

Import the Heading primitive.

Hello world
import * as React from 'react';
import { Heading } from '@aws-amplify/ui-react';

export const DefaultHeadingExample = () => {
  return <Heading>Hello world</Heading>;
};

Heading levels

Use the level prop to change the heading level (e.g., h1 - h6). Default heading level is 6 and available options are 1, 2, 3, 4, 5 and 6.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6
Default (level 6)
import * as React from 'react';
import { Heading } from '@aws-amplify/ui-react';

export const HeadingLevelExample = () => {
  return (
    <>
      <Heading level={1}>Heading 1</Heading>
      <Heading level={2}>Heading 2</Heading>
      <Heading level={3}>Heading 3</Heading>
      <Heading level={4}>Heading 4</Heading>
      <Heading level={5}>Heading 5</Heading>
      <Heading level={6}>Heading 6</Heading>
      <Heading>Default (level 6)</Heading>
    </>
  );
};

Truncate

The isTruncated prop will render an ellipsis when the Heading text exceeds its allowed width.

Hello world Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

import { Heading } from '@aws-amplify/ui-react';

export const TruncatedHeading = () => {
  return (
    <Heading isTruncated={true} level={3}>
      Hello world Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
      do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
      minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
      ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
      velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
      cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
      est laborum.
    </Heading>
  );
};

CSS Styling

Theme

You can customize the appearance of all Heading components in your application with a Theme.

Heading Theme Source

Title

Default
import { Heading, Flex, ThemeProvider, Theme } from '@aws-amplify/ui-react';

const theme: Theme = {
  name: 'heading-theme',
  tokens: {
    components: {
      heading: {
        color: { value: '{colors.blue.80}' },

        1: {
          fontSize: { value: '{fontSizes.xxl}' },
          fontWeight: { value: '{fontWeights.bold}' },
        },
        6: {
          fontSize: { value: '{fontSizes.large}' },
          fontWeight: { value: '{fontWeights.normal}' },
        },
      },
    },
  },
};

export const HeadingThemeExample = () => (
  <ThemeProvider theme={theme} colorMode="light">
    <Flex direction="column">
      <Heading level={1}>Title</Heading>
      <Heading>Default</Heading>
    </Flex>
  </ThemeProvider>
);

Target classes

ClassDescription
amplify-headingTop level element that wraps the Heading primitive
  • --amplify-components-heading-1-font-size
  • --amplify-components-heading-1-font-weight
  • --amplify-components-heading-2-font-size
  • --amplify-components-heading-2-font-weight
  • --amplify-components-heading-3-font-size
  • --amplify-components-heading-3-font-weight
  • --amplify-components-heading-4-font-size
  • --amplify-components-heading-4-font-weight
  • --amplify-components-heading-5-font-size
  • --amplify-components-heading-5-font-weight
  • --amplify-components-heading-6-font-size
  • --amplify-components-heading-6-font-weight
  • --amplify-components-heading-color
  • --amplify-components-heading-line-height

Global styling

To override styling on all Headings, you can set the Amplify CSS variables or use the built-in .amplify-heading class.

Hello world

/* styles.css */
:root {
  --amplify-components-heading-color: gray;
}
/* OR */
.amplify-heading {
  color: gray;
}

Override styles for any Heading component h1 - h6 using the .amplify-heading--[LEVEL] classes.

Small and italic

Big and bold

/* styles.css */
.amplify-heading--1 {
  font-size: 1rem;
  font-style: italic;
}

.amplify-heading--6 {
  font-size: 2rem;
  font-weight: bold;
}
import './styles.css';

<Heading level={1}>Small and italic</Heading>
<Heading>Big and bold</Heading>

Local styling

To override styling on a specific Heading, you can use a class selector or style props.

Using a class selector:

Hello world

/* styles.css */
.heading-blue {
  color: var(--amplify-colors-blue-80);
}
import './styles.css';

<Heading className="heading-blue" level={3}>
  Hello world
</Heading>;

Using style props:

Hello world

<Heading level={3} color="green" fontWeight="bold">
  Hello world
</Heading>

Amplify open source software, documentation and community are supported by Amazon Web Services.

© 2024 Amazon Web Services, Inc. and its affiliates. All rights reserved. View the site terms and privacy policy.

Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.