Alignment in React Timeline
24 Sep 202621 minutes to read
The React Timeline component allows you to control the positioning of content using the align property, which accepts values Before, After, Alternate, or AlternateReverse. When both content and oppositeContent are configured for an item ItemDirective, the oppositeContent will be displayed parallel to the main content, creating a balanced layout on opposite sides of the timeline.
Before
The Before alignment positions content strategically based on orientation. For horizontal orientation, the main content appears at the top with oppositeContent at the bottom. For vertical orientation, content is positioned on the left side while oppositeContent appears on the right side.
import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='Before'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='Before'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);/* Represents the styles for loader */
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#timeline {
height: 350px;
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion EJ2 React Timeline Sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/35.2.12/tailwind3.css" rel="stylesheet">
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='element' style="margin-top: 30px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>After
The After alignment reverses the content positioning compared to Before alignment. For horizontal orientation, the main content is placed at the bottom with oppositeContent at the top. For vertical orientation, content appears on the right side while oppositeContent is positioned on the left side.
import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='After'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='After'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);/* Represents the styles for loader */
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#timeline {
height: 350px;
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion EJ2 React Timeline Sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/35.2.12/tailwind3.css" rel="stylesheet">
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='element' style="margin-top: 30px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>Alternate
The Alternate alignment creates a dynamic zigzag pattern where timeline items switch positions alternately. This arrangement provides visual variety and works effectively for showcasing parallel events or comparisons, regardless of whether the React Timeline orientation is horizontal or vertical.
import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='Alternate'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='Alternate'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);/* Represents the styles for loader */
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#timeline {
height: 350px;
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion EJ2 React Timeline Sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/35.2.12/tailwind3.css" rel="stylesheet">
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='element' style="margin-top: 30px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>Alternate Reverse
The AlternateReverse alignment creates the opposite pattern of Alternate alignment, where timeline items are arranged in reverse alternating order. This provides another visual variation for displaying data with an inverted alternating pattern, maintaining effectiveness across both React Timeline orientations.
import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='AlternateReverse'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);import * as React from "react";
import * as ReactDOM from 'react-dom/client';
import { TimelineComponent, ItemsDirective, ItemDirective } from '@syncfusion/ej2-react-layouts';
function App() {
return (
<div id='timeline'>
<TimelineComponent align='AlternateReverse'>
<ItemsDirective>
<ItemDirective content='ReactJs' oppositeContent='Owned by Facebook' />
<ItemDirective content='Angular' oppositeContent='Owned by Google' />
<ItemDirective content='VueJs' oppositeContent='Owned by Evan You' />
<ItemDirective content='Svelte' oppositeContent='Owned by Rich Harris' />
</ItemsDirective>
</TimelineComponent>
</div>
);
}
export default App;
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);/* Represents the styles for loader */
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#timeline {
height: 350px;
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion EJ2 React Timeline Sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/35.2.12/tailwind3.css" rel="stylesheet">
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='element' style="margin-top: 30px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>