Grid

24 Grids System。

Design concept#

100%
25%
25%
25%
25%
33.33%
33.33%
33.33%
50%
50%
66.66%
33.33%

In most business situations, Ant Design needs to solve a lot of information storage problems within the design area, so based on 12 Grids System, we divided the design area into 24 sections.

We name the divided area 'box'. We suggest four boxes for horizontal arrangement at most, one at least. Boxes are proportional to the entire screen as shown in the picture above. To ensure a high level of visual comfort, we customize the typography inside of the box based on the box unit.

Outline#

In the grid system, we define the frame outside the information area based on row and column, to ensure that every area can have stable arrangement.

Following is a brief look at how it works:

  • Establish a set of column in the horizontal space defined by row (abbreviated col)

  • Your content elements should be placed directly in the col, and only col should be placed directly in row

  • The column grid system is a value of 1-24 to represent its range spans. For example, three columns of equal width can be created by <Col span={8} />.

  • If the sum of col spans in a row are more than 24, then the overflowing col as a whole will start a new line arrangement.

Our grid systems base on Flex layout to allow the elements within the parent to be aligned horizontally - left, center, right, wide arrangement, and decentralized arrangement. The Grid system also supports vertical alignment - top aligned, vertically centered, bottom-aligned. You can also define the order of elements by using order.

Layout uses a 24 grid layout to define the width of each "box", but does not rigidly adhere to the grid layout.

Examples

col
col-12
col-12
col-8
col-8
col-8
col-6
col-6
col-6
col-6

From the stack to the horizontal arrangement.

You can create a basic grid system by using a single set of Row and Col grid assembly, all of the columns (Col) must be placed in Row.

expand codeexpand code
import { Row, Col } from 'antd';

ReactDOM.render(
  <>
    <Row>
      <Col span={24}>col</Col>
    </Row>
    <Row>
      <Col span={12}>col-12</Col>
      <Col span={12}>col-12</Col>
    </Row>
    <Row>
      <Col span={8}>col-8</Col>
      <Col span={8}>col-8</Col>
      <Col span={8}>col-8</Col>
    </Row>
    <Row>
      <Col span={6}>col-6</Col>
      <Col span={6}>col-6</Col>
      <Col span={6}>col-6</Col>
      <Col span={6}>col-6</Col>
    </Row>
  </>,
  mountNode,
);
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6

You can use the gutter property of Row as grid spacing, we recommend set it to (16 + 8n) px. (n stands for natural number.)

You can set it to a object like { xs: 8, sm: 16, md: 24, lg: 32 } for responsive design.

You can use a array to set vertical spacing, [horizontal, vertical] [16, { xs: 8, sm: 16, md: 24, lg: 32 }].

vertical gutter was supported after 3.24.0.

expand codeexpand code
import { Row, Col, Divider } from 'antd';

const style = { background: '#0092ff', padding: '8px 0' };

ReactDOM.render(
  <>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Horizontal
    </Divider>
    <Row gutter={16}>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
    </Row>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Responsive
    </Divider>
    <Row gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
    </Row>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Vertical
    </Divider>
    <Row gutter={[16, 24]}>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
      <Col className="gutter-row" span={6}>
        <div style={style}>col-6</div>
      </Col>
    </Row>
  </>,
  mountNode,
);
.gutter-box {
  padding: 8px 0;
  background: #00a0e9;
}
col-8
col-8
col-6 col-offset-6
col-6 col-offset-6
col-12 col-offset-6

Offset can set the column to the right side. For example, using offset = {4} can set the element shifted to the right four columns width.

expand codeexpand code
import { Row, Col } from 'antd';

ReactDOM.render(
  <>
    <Row>
      <Col span={8}>col-8</Col>
      <Col span={8} offset={8}>
        col-8
      </Col>
    </Row>
    <Row>
      <Col span={6} offset={6}>
        col-6 col-offset-6
      </Col>
      <Col span={6} offset={6}>
        col-6 col-offset-6
      </Col>
    </Row>
    <Row>
      <Col span={12} offset={6}>
        col-12 col-offset-6
      </Col>
    </Row>
  </>,
  mountNode,
);
col-18 col-push-6
col-6 col-pull-18

By using push andpull class you can easily change column order.

expand codeexpand code
import { Row, Col } from 'antd';

ReactDOM.render(
  <Row>
    <Col span={18} push={6}>
      col-18 col-push-6
    </Col>
    <Col span={6} pull={18}>
      col-6 col-pull-18
    </Col>
  </Row>,
  mountNode,
);
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4
col-4

Child elements depending on the value of the start,center, end,space-between, space-around, which are defined in its parent node typesetting mode.

expand codeexpand code
import { Row, Col, Divider } from 'antd';

ReactDOM.render(
  <>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      sub-element align left
    </Divider>
    <Row justify="start">
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
    </Row>

    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      sub-element align center
    </Divider>
    <Row justify="center">
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
    </Row>

    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      sub-element align right
    </Divider>
    <Row justify="end">
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
    </Row>

    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      sub-element monospaced arrangement
    </Divider>
    <Row justify="space-between">
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
    </Row>

    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      sub-element align full
    </Divider>
    <Row justify="space-around">
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
      <Col span={4}>col-4</Col>
    </Row>
  </>,
  mountNode,
);
#components-grid-demo-flex [class~='ant-row'] {
  background: rgba(128, 128, 128, 0.08);
}

col-4

col-4

col-4

col-4

col-4

col-4

col-4

col-4

col-4

col-4

col-4

col-4

Child elements vertically aligned.

expand codeexpand code
import { Row, Col, Divider } from 'antd';

const DemoBox = props => <p className={`height-${props.value}`}>{props.children}</p>;

ReactDOM.render(
  <>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Align Top
    </Divider>
    <Row justify="center" align="top">
      <Col span={4}>
        <DemoBox value={100}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={50}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={120}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={80}>col-4</DemoBox>
      </Col>
    </Row>

    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Align Middle
    </Divider>
    <Row justify="space-around" align="middle">
      <Col span={4}>
        <DemoBox value={100}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={50}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={120}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={80}>col-4</DemoBox>
      </Col>
    </Row>

    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Align Bottom
    </Divider>
    <Row justify="space-between" align="bottom">
      <Col span={4}>
        <DemoBox value={100}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={50}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={120}>col-4</DemoBox>
      </Col>
      <Col span={4}>
        <DemoBox value={80}>col-4</DemoBox>
      </Col>
    </Row>
  </>,
  mountNode,
);
#components-grid-demo-flex-align [class~='ant-row'] {
  background: rgba(128, 128, 128, 0.08);
}
1 col-order-4
2 col-order-3
3 col-order-2
4 col-order-1

To change the element sort by order.

expand codeexpand code
import { Row, Col } from 'antd';

ReactDOM.render(
  <Row>
    <Col span={6} order={4}>
      1 col-order-4
    </Col>
    <Col span={6} order={3}>
      2 col-order-3
    </Col>
    <Col span={6} order={2}>
      3 col-order-2
    </Col>
    <Col span={6} order={1}>
      4 col-order-1
    </Col>
  </Row>,
  mountNode,
);
#components-grid-demo-flex-order [class~='ant-row'] {
  background: rgba(128, 128, 128, 0.08);
}
2 / 5
3 / 5
100px
Fill Rest
1 1 200px
0 1 300px

Col provides flex prop to support fill rest.

expand codeexpand code
import { Row, Col, Divider } from 'antd';

ReactDOM.render(
  <>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Percentage columns
    </Divider>
    <Row>
      <Col flex={2}>2 / 5</Col>
      <Col flex={3}>3 / 5</Col>
    </Row>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Fill rest 
    </Divider>
    <Row>
      <Col flex="100px">100px</Col>
      <Col flex="auto">Fill Rest</Col>
    </Row>
    <Divider orientation="left" style={{ color: '#333', fontWeight: 'normal' }}>
      Raw flex style
    </Divider>
    <Row>
      <Col flex="1 1 200px">1 1 200px</Col>
      <Col flex="0 1 300px">0 1 300px</Col>
    </Row>
  </>,
  mountNode,
);
Col
Col
Col

Referring to the Bootstrap responsive design, here preset six dimensions: xs sm md lg xl.

expand codeexpand code
import { Row, Col } from 'antd';

ReactDOM.render(
  <Row>
    <Col xs={2} sm={4} md={6} lg={8} xl={10}>
      Col
    </Col>
    <Col xs={20} sm={16} md={12} lg={8} xl={4}>
      Col
    </Col>
    <Col xs={2} sm={4} md={6} lg={8} xl={10}>
      Col
    </Col>
  </Row>,
  mountNode,
);
Col
Col
Col

span pull push offset order property can be embedded into xs sm md lg xl properties to use, where xs={6} is equivalent to xs={{span: 6}}.

expand codeexpand code
import { Row, Col } from 'antd';

ReactDOM.render(
  <Row>
    <Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 2 }}>
      Col
    </Col>
    <Col xs={{ span: 11, offset: 1 }} lg={{ span: 6, offset: 2 }}>
      Col
    </Col>
    <Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 2 }}>
      Col
    </Col>
  </Row>,
  mountNode,
);
Horizontal Gutter (px):
81624324048
Vertical Gutter (px):
81624324048
Column Count:
2346812
Column
Column
Column
Column
Column
Column
Column
Column
<Row gutter={[16, 16]}>
  <Col span={6} />
  <Col span={6} />
  <Col span={6} />
  <Col span={6} />
</Row>
<Row gutter={[16, 16]}>
  <Col span={6} />
  <Col span={6} />
  <Col span={6} />
  <Col span={6} />
</Row>

A simple playground for column count and gutter.

expand codeexpand code
import { Row, Col, Slider } from 'antd';

class App extends React.Component {
  gutters = {};

  vgutters = {};

  colCounts = {};

  constructor() {
    super();
    this.state = {
      gutterKey: 1,
      vgutterKey: 1,
      colCountKey: 2,
    };
    [8, 16, 24, 32, 40, 48].forEach((value, i) => {
      this.gutters[i] = value;
    });
    [8, 16, 24, 32, 40, 48].forEach((value, i) => {
      this.vgutters[i] = value;
    });
    [2, 3, 4, 6, 8, 12].forEach((value, i) => {
      this.colCounts[i] = value;
    });
  }

  onGutterChange = gutterKey => {
    this.setState({ gutterKey });
  };

  onVGutterChange = vgutterKey => {
    this.setState({ vgutterKey });
  };

  onColCountChange = colCountKey => {
    this.setState({ colCountKey });
  };

  render() {
    const { gutterKey, vgutterKey, colCountKey } = this.state;
    const cols = [];
    const colCount = this.colCounts[colCountKey];
    let colCode = '';
    for (let i = 0; i < colCount; i++) {
      cols.push(
        <Col key={i.toString()} span={24 / colCount}>
          <div>Column</div>
        </Col>,
      );
      colCode += `  <Col span={${24 / colCount}} />\n`;
    }
    return (
      <>
        <span style={{ marginRight: 6 }}>Horizontal Gutter (px): </span>
        <div style={{ width: '50%' }}>
          <Slider
            min={0}
            max={Object.keys(this.gutters).length - 1}
            value={gutterKey}
            onChange={this.onGutterChange}
            marks={this.gutters}
            step={null}
          />
        </div>
        <span style={{ marginRight: 6 }}>Vertical Gutter (px): </span>
        <div style={{ width: '50%' }}>
          <Slider
            min={0}
            max={Object.keys(this.vgutters).length - 1}
            value={vgutterKey}
            onChange={this.onVGutterChange}
            marks={this.vgutters}
            step={null}
          />
        </div>
        <span style={{ marginRight: 6 }}>Column Count:</span>
        <div style={{ width: '50%', marginBottom: 48 }}>
          <Slider
            min={0}
            max={Object.keys(this.colCounts).length - 1}
            value={colCountKey}
            onChange={this.onColCountChange}
            marks={this.colCounts}
            step={null}
          />
        </div>
        <Row gutter={[this.gutters[gutterKey], this.vgutters[vgutterKey]]}>{cols}</Row>
        <Row gutter={[this.gutters[gutterKey], this.vgutters[vgutterKey]]}>{cols}</Row>
        <pre>{`<Row gutter={[${this.gutters[gutterKey]}, ${this.vgutters[vgutterKey]}]}>\n${colCode}</Row>`}</pre>
        <pre>{`<Row gutter={[${this.gutters[gutterKey]}, ${this.vgutters[vgutterKey]}]}>\n${colCode}</Row>`}</pre>
      </>
    );
  }
}

ReactDOM.render(<App />, mountNode);
#components-grid-demo-playground [class~='ant-col'] {
  background: transparent;
  border: 0;
}
#components-grid-demo-playground [class~='ant-col'] > div {
  height: 120px;
  font-size: 14px;
  line-height: 120px;
  background: #0092ff;
  border-radius: 4px;
}
#components-grid-demo-playground pre {
  padding: 8px 16px;
  font-size: 13px;
  background: #f9f9f9;
  border-radius: 6px;
}
Current break point: 

Use useBreakpoint Hook povide personalized layout.

expand codeexpand code
import { Row, Col, Grid } from 'antd';

const { useBreakpoint } = Grid;

function UseBreakpointDemo() {
  const screens = useBreakpoint();

  return (
    <Row>
      <Col>
        Current break point:&nbsp;
        {Object.entries(screens)
          .filter(screen => !!screen[1])
          .map(screen => screen[0])
          .join(' ')}
      </Col>
    </Row>
  );
}

ReactDOM.render(<UseBreakpointDemo />, mountNode);

API#

If the Ant Design grid layout component does not meet your needs, you can use the excellent layout components of the community:

Row#

PropertyDescriptionTypeDefaultVersion
alignvertical alignmenttop | middle | bottomtop
gutterspacing between grids, could be a number or a object like { xs: 8, sm: 16, md: 24}. or you can use array to make horizontal and vertical spacing work at the same time [horizontal, vertical]number/object/array0
justifyhorizontal arrangementstart | end | center | space-around | space-betweenstart

Col#

PropertyDescriptionTypeDefaultVersion
flexflex layout stylestring | number-
offsetthe number of cells to offset Col from the leftnumber0
orderraster ordernumber0
pullthe number of cells that raster is moved to the leftnumber0
pushthe number of cells that raster is moved to the rightnumber0
spanraster number of cells to occupy, 0 corresponds to display: nonenumbernone
xs<576px and also default setting, could be a span value or an object containing above propsnumber|object-
sm≥576px, could be a span value or an object containing above propsnumber|object-
md≥768px, could be a span value or an object containing above propsnumber|object-
lg≥992px, could be a span value or an object containing above propsnumber|object-
xl≥1200px, could be a span value or an object containing above propsnumber|object-
xxl≥1600px, could be a span value or an object containing above propsnumber|object-

The breakpoints of responsive grid follow BootStrap 4 media queries rules (not including occasionally part).

Layout