Introduction
Filament’s grid system allows you to create responsive, multi-column layouts using any layout component. Filament provides a set of built-in layout components to help you build these: You may also create your own custom layout components to display components however you wish.Grid system
All layout components have acolumns() method that you can use in a couple of different ways:
- You can pass an integer like
columns(2). This integer is the number of columns used on thelgbreakpoint and higher. All smaller devices will have just 1 column. - You can pass an array, where the key is the breakpoint and the value is the number of columns. For example,
columns(['md' => 2, 'xl' => 4])will create a 2 column layout on medium devices, and a 4 column layout on extra large devices. The default breakpoint for smaller devices uses 1 column, unless you use adefaultarray key.
sm, md, lg, xl, 2xl) are defined by Tailwind, and can be found in the Tailwind documentation.
As well as allowing a static value, the columns() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
columns() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
Grid column spans
In addition to specifying how many columns a layout component should have, you may also specify how many columns a component should fill within the parent grid, using thecolumnSpan() method. This method accepts an integer or an array of breakpoints and column spans:
- You can pass an integer like
columnSpan(2). This integer is the number of columns that are consumed on thelgbreakpoint and higher. All smaller devices span just 1 column. columnSpan(['md' => 2, 'xl' => 4])will make the component fill up to 2 columns on medium devices, and up to 4 columns on extra large devices. The default breakpoint for smaller devices uses 1 column, unless you use adefaultarray key.columnSpan('full')will make the component fill the full width of the parent grid on thelgbreakpoint and higher, regardless of how many columns there are. All smaller devices span just 1 column.columnSpanFull()will make the component fill the full width of the parent grid on all devices, regardless of how many columns it has.
As well as allowing a static value, the columnSpan() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
columnSpan() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
Grid column starts
If you want to start a component in a grid at a specific column, you can use thecolumnStart() method. This method accepts an integer, or an array of breakpoints and which column the component should start at:
- You can pass an integer like
columnStart(2). This integer is column that the component will start on for thelgbreakpoint and higher. All smaller devices start the component on the first column. columnStart(['md' => 2, 'xl' => 4])will make the component start at column 2 on medium devices, and at column 4 on extra large devices. The default breakpoint for smaller devices uses 1 column, unless you use adefaultarray key.
As well as allowing a static value, the columnStart() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
columnStart() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
Grid column ordering
If you want to control the visual order of components in a grid without changing their position in the markup, you can use thecolumnOrder() method. This method accepts an integer, a closure, or an array of breakpoints and order values:
- You can pass an integer like
columnOrder(2). This integer is the order that the component will appear in for thelgbreakpoint and higher. All smaller devices use the default order, unless you use adefaultarray key. columnOrder(['md' => 2, 'xl' => 4])will set the component’s order to 2 on medium devices, and to 4 on extra large devices. The default breakpoint for smaller devices uses the default order, unless you use adefaultarray key.columnOrder(fn () => 1)will dynamically calculate the order using a closure.
As well as allowing a static value, the columnOrder() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
columnOrder() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
An example of a responsive grid layout
In this example, we have a schema with a section layout component. Since all layout components support thecolumns() method, we can use it to create a responsive grid layout within the section itself.
We pass an array to columns() as we want to specify different numbers of columns for different breakpoints. On devices smaller than the sm Tailwind breakpoint, we want to have 1 column, which is default. On devices larger than the sm breakpoint, we want to have 3 columns. On devices larger than the xl breakpoint, we want to have 6 columns. On devices larger than the 2xl breakpoint, we want to have 8 columns.
Inside the section, we have a text input. Since text inputs are form fields and all components have a columnSpan() method, we can use it to specify how many columns the text input should fill. On devices smaller than the sm breakpoint, we want the text input to fill 1 column, which is default. On devices larger than the sm breakpoint, we want the text input to fill 2 columns. On devices larger than the xl breakpoint, we want the text input to fill 3 columns. On devices larger than the 2xl breakpoint, we want the text input to fill 4 columns.
Additionally, we’re using the columnOrder() method to control the visual order of components in the grid based on screen size. This allows us to change the display order without altering the markup structure.
xl breakpoint, the email field will appear first followed by the name field. On screens larger than the xl breakpoint, the order is reversed with the name field appearing first followed by the email field.
Basic layout components
Grid component
All layout components support thecolumns() method, but you also have access to an additional Grid component. If you feel that your schema would benefit from an explicit grid syntax with no extra styling, it may be useful to you. Instead of using the columns() method, you can pass your column configuration directly to Grid::make():
Flex component
TheFlex component allows you to define layouts with flexible widths, using flexbox. This component does not use Filament’s grid system.
grow() to consume available horizontal space, without affecting the amount of space needed to render the second section. This creates a flexible width sidebar effect.
The from() method is used to control the Tailwind breakpoint (sm, md, lg, xl, 2xl) at which the horizontally-split layout should be used. In this example, the horizontally-split layout will be used on medium devices and larger. On smaller devices, the sections will stack on top of each other.
As well as allowing static values, the grow() and from() methods also accept functions to dynamically calculate them. You can inject various utilities into the functions as parameters.
grow() and from() methods also accept functions to dynamically calculate them. You can inject various utilities into the functions as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
Fieldset component
You may want to group fields into a Fieldset. Each fieldset has a label, a border, and a two-column grid by default:As well as allowing a static label, the make() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
make() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
Removing the border from a fieldset
You can remove the container border from a fieldset using thecontained(false) method:
As well as allowing a static value, the contained() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
contained() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
Using container queries
In addition to traditional breakpoints based on the size of the viewport, you can also use container queries to create responsive layouts based on the size of a parent container. This is particularly useful when the size of the parent container is not directly tied to the size of the viewport. For example, when using a collapsible sidebar alongside the content, the content area dynamically adjusts its size depending on the collapse state of the sidebar. The foundation of a container query is the container itself. The container is the element whose width determines the layout. To designate an element as a container, use thegridContainer() method on it. For instance, if you want to define the number of grid columns in a [Grid component] based on its width:
@md to define the number of grid columns when the container’s width is at least 448px, and @xl for when the width is at least 576px.
columnSpan(), columnStart(), and columnOrder() methods:
@xl breakpoint (576px), the email field will appear first followed by the name field. When the container width is at least 576px, the order is reversed with the name field appearing first followed by the email field.
Supporting container queries on older browsers
Container queries are not yet widely supported in browsers compared to traditional breakpoints. To support older browsers, you can define an additional layer of breakpoints alongside the container breakpoints. By prefixing the traditional breakpoint with!@, you can specify that the fallback breakpoint should be used when container queries are not supported in the browser.
For example, if you want to use the @md container breakpoint for the grid columns but also support older browsers, you can define the !@md fallback breakpoint, which will be applied when container queries are unavailable:
!@ fallback breakpoints in the columnSpan(), columnStart(), and columnOrder() methods:
Controlling spacing between components
Reducing space between components
Thedense() method creates a more compact layout by reducing the spacing between components by 50%:
Removing space between components
Thegap(false) method removes space between components:
Adding extra HTML attributes to a layout component
You can pass extra HTML attributes to the component via theextraAttributes() method, which will be merged onto its outer HTML element. The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value:
As well as allowing a static value, the extraAttributes() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
extraAttributes() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
extraAttributes() multiple times will overwrite the previous attributes. If you wish to merge the attributes instead, you can pass merge: true to the method.