Most Elementor sites end up with one pattern that the built-in widgets don't quite cover: a branded feature card, a pricing row with rules, a block fed by an API. Rebuilding it by hand on every page drifts. A custom widget turns it into one component that editors drop in and style from the panel.

Here's a minimal Feature Card widget, packaged as its own plugin, with two details most tutorials skip: the CSS loads only on pages that use the widget, and the style controls generate scoped CSS instead of inline styles.

The plugin file

feature-card-widget/ ├── feature-card-widget.php ├── widgets/class-feature-card-widget.php └── assets/feature-card.css 
<?php /** * Plugin Name: Feature Card Widget * Requires Plugins: elementor */ if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'elementor/widgets/register', function ( $widgets_manager ) { require_once __DIR__ . '/widgets/class-feature-card-widget.php'; $widgets_manager->register( new \Feature_Card_Widget() ); } ); add_action( 'wp_enqueue_scripts', function () { wp_register_style( 'feature-card-widget', plugins_url( 'assets/feature-card.css', __FILE__ ), [], '1.0.0' ); } ); 

The class file is only loaded inside the Elementor hook, so nothing breaks if Elementor is off. The stylesheet is registered, not enqueued. The widget asks for it below.

Keep widgets in a plugin, not the theme: they're functionality, and they should survive a theme switch.

The widget class

<?php use Elementor\Controls_Manager; use Elementor\Widget_Base; class Feature_Card_Widget extends Widget_Base { public function get_name() { return 'feature_card'; } // permanent ID, don't rename later public function get_title() { return esc_html__( 'Feature Card', 'feature-card-widget' ); } public function get_icon() { return 'eicon-info-box'; } public function get_categories() { return [ 'general' ]; } public function get_style_depends() { return [ 'feature-card-widget' ]; } protected function register_controls() { $this->start_controls_section( 'content', [ 'label' => esc_html__( 'Content', 'feature-card-widget' ), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'title', [ 'label' => esc_html__( 'Title', 'feature-card-widget' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Fast delivery', 'feature-card-widget' ), ] ); $this->add_control( 'link', [ 'label' => esc_html__( 'Link', 'feature-card-widget' ), 'type' => Controls_Manager::URL, ] ); $this->end_controls_section(); $this->start_controls_section( 'style', [ 'label' => esc_html__( 'Card', 'feature-card-widget' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'background_color', [ 'label' => esc_html__( 'Background', 'feature-card-widget' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .feature-card' => 'background-color: {{VALUE}};', ], ] ); $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); $has_link = ! empty( $settings['link']['url'] ); if ( $has_link ) { $this->add_link_attributes( 'card_link', $settings['link'] ); } ?> <div class="feature-card"> <h3 class="feature-card__title"><?php echo esc_html( $settings['title'] ); ?></h3> <?php if ( $has_link ) : ?> <a <?php $this->print_render_attribute_string( 'card_link' ); ?>> <?php esc_html_e( 'Learn more', 'feature-card-widget' ); ?> </a> <?php endif; ?> </div> <?php } } 

What's doing the work:

  • get_style_depends() returns the handle registered in the plugin file. Elementor enqueues it only on pages where this widget appears, and in the editor preview. An unregistered handle does nothing, which is a common reason "my widget CSS doesn't load".
  • selectors on the color control: Elementor writes CSS scoped to this widget instance ({{WRAPPER}}), so editors get a live preview and you print no inline styles.
  • get_settings_for_display() rather than get_settings(), so dynamic tags resolve.
  • add_link_attributes() builds href, target and rel from the URL control, including the "new window" and "nofollow" switches, and escapes them.
  • Everything else printed goes through esc_html().

Activate the plugin, open a page in Elementor and search the panel for "Feature Card".

Mistakes I see in older tutorials

Old way Use instead
_register_controls() (old underscore name) register_controls()
elementor/widgets/widgets_registered + register_widget_type() elementor/widgets/register + register() (the old hook is deprecated and scheduled for removal in 4.3)
Enqueuing the widget CSS on every page Register it, return it from get_style_depends()
Hard-coded colors Style controls with selectors

Where to go next

Swap add_control() for add_responsive_control() on spacing, add Group_Control_Typography for the title, or use a REPEATER for bullet lists. You can also add a field to a built-in widget without writing a new one, through the elementor/element/{widget}/{section}/before_section_end hook.

The full guide, with the description field, the stylesheet, reading ACF fields inside render() and extending the Heading widget, is here: How to create a custom Elementor widget.