To achieve this, you have two options. Option a) involves dynamically manipulating the DOM tree with JavaScript, while option b) requires coding all your different rows with the correct number of columns for each viewport and then hiding and showing them at specific breakpoints using a media query.
Using JavaScript allows you to avoid duplicating HTML markup. A purely CSS-based solution would necessitate duplicating the markup or content.
For option b), you would initially display 2 rows with 3 columns each and hide the additional 3 rows with 2 columns each using display: none;
. As the viewport width decreases, you would hide the visible rows and reveal the hidden ones by toggling the display properties accordingly.