Skip to content

Card

Card is a layout utility component that provides a styled container with optional title, border, shadow, rounded corners, and configurable content sections. It’s commonly used for card-like elements or content blocks.


<script setup>
defineProps({
title: String,
titleResponsive: Boolean,
titleTag: {
type: String,
default: "h2",
},
bordered: {
type: Boolean,
default: true,
},
shadow: Boolean,
rounded: {
type: Boolean,
default: true,
},
striped: {
type: Boolean,
default: true,
},
paddless: Boolean,
dimmed: Boolean,
});
</script>
<template>
<div
:class="[
bordered ? 'border border-gray-300' : '',
shadow ? 'shadow-md' : '',
rounded ? 'rounded-md' : '',
dimmed ? 'bg-gray-100' : 'bg-white',
]"
>
<div
v-if="title"
:class="[
striped ? 'border-b border-gray-300 p-4' : 'px-4 pt-4',
'flex items-center justify-between',
]"
>
<component
:is="titleTag"
:class="[
'font-bold',
titleResponsive ? 'text-lg lg:text-xl' : 'text-xl',
]"
>
{{ title }}
</component>
<slot name="action" />
</div>
<div :class="[paddless ? '' : 'p-4']">
<slot />
</div>
<div
v-if="$slots.footer"
class="border-t border-gray-300 p-4"
>
<slot name="footer" />
</div>
</div>
</template>
PropTypeDefaultDescription
titleStringOptional title displayed at the top section.
titleResponsiveBooleanfalseIf true, the title adapts to screen size responsively.
titleTagString'h2'The HTML tag used to render the title (e.g., 'h1', 'h2', 'div').
borderedBooleantrueWhether the card should have a border.
shadowBooleanfalseAdds a shadow if true.
roundedBooleantrueWhether the card has rounded corners.
stripedBooleantrueAdds a bottom border under the title for separation.
paddlessBooleanfalseRemoves default padding inside the card body if set to true.
dimmedBooleanfalseIf true, applies a dimmed background style to the card.
SlotDescription
defaultThe main content inside the card.
actionShown next to the title (e.g., buttons or icons).
footerFooter section shown at the bottom, with top border.